|
|
3e8f86 |
From c486d01297a366aae8dcd3f715d0bfd8b995949b Mon Sep 17 00:00:00 2001
|
|
|
3e8f86 |
From: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
3e8f86 |
Date: Mon, 8 Feb 2021 09:27:20 -0800
|
|
|
3e8f86 |
Subject: [PATCH 1/2] linux_usbfs: Accept sysfs attributes not terminated with
|
|
|
3e8f86 |
newline
|
|
|
3e8f86 |
|
|
|
3e8f86 |
Benjamin Berg reports that some CI systems that simulate sysfs devices
|
|
|
3e8f86 |
are causing libusb to report errors because such systems are not
|
|
|
3e8f86 |
conforming to the sysfs pattern of terminating attribute values with a
|
|
|
3e8f86 |
newline character. Reduce the severity of encountering such
|
|
|
3e8f86 |
non-conforming attibute values from an error that prevents enumeration
|
|
|
3e8f86 |
to a warning message.
|
|
|
3e8f86 |
|
|
|
3e8f86 |
Closes #857
|
|
|
3e8f86 |
|
|
|
3e8f86 |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
3e8f86 |
---
|
|
|
3e8f86 |
libusb/os/linux_usbfs.c | 12 +++++++-----
|
|
|
3e8f86 |
libusb/version_nano.h | 2 +-
|
|
|
3e8f86 |
2 files changed, 8 insertions(+), 6 deletions(-)
|
|
|
3e8f86 |
|
|
|
3e8f86 |
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
|
|
|
3e8f86 |
index 4882c0f..ebf8cfe 100644
|
|
|
3e8f86 |
--- a/libusb/os/linux_usbfs.c
|
|
|
3e8f86 |
+++ b/libusb/os/linux_usbfs.c
|
|
|
3e8f86 |
@@ -505,7 +505,7 @@ static int read_sysfs_attr(struct libusb_context *ctx,
|
|
|
3e8f86 |
if (fd < 0)
|
|
|
3e8f86 |
return fd;
|
|
|
3e8f86 |
|
|
|
3e8f86 |
- r = read(fd, buf, sizeof(buf));
|
|
|
3e8f86 |
+ r = read(fd, buf, sizeof(buf) - 1);
|
|
|
3e8f86 |
if (r < 0) {
|
|
|
3e8f86 |
r = errno;
|
|
|
3e8f86 |
close(fd);
|
|
|
3e8f86 |
@@ -523,16 +523,18 @@ static int read_sysfs_attr(struct libusb_context *ctx,
|
|
|
3e8f86 |
return 0;
|
|
|
3e8f86 |
}
|
|
|
3e8f86 |
|
|
|
3e8f86 |
- /* The kernel does *not* NULL-terminate the string, but every attribute
|
|
|
3e8f86 |
+ /* The kernel does *not* NUL-terminate the string, but every attribute
|
|
|
3e8f86 |
* should be terminated with a newline character. */
|
|
|
3e8f86 |
if (!isdigit(buf[0])) {
|
|
|
3e8f86 |
usbi_err(ctx, "attribute %s doesn't have numeric value?", attr);
|
|
|
3e8f86 |
return LIBUSB_ERROR_IO;
|
|
|
3e8f86 |
} else if (buf[r - 1] != '\n') {
|
|
|
3e8f86 |
- usbi_err(ctx, "attribute %s doesn't end with newline?", attr);
|
|
|
3e8f86 |
- return LIBUSB_ERROR_IO;
|
|
|
3e8f86 |
+ usbi_warn(ctx, "attribute %s doesn't end with newline?", attr);
|
|
|
3e8f86 |
+ } else {
|
|
|
3e8f86 |
+ /* Remove the terminating newline character */
|
|
|
3e8f86 |
+ r--;
|
|
|
3e8f86 |
}
|
|
|
3e8f86 |
- buf[r - 1] = '\0';
|
|
|
3e8f86 |
+ buf[r] = '\0';
|
|
|
3e8f86 |
|
|
|
3e8f86 |
errno = 0;
|
|
|
3e8f86 |
value = strtol(buf, &endptr, 10);
|
|
|
3e8f86 |
--
|
|
|
3e8f86 |
2.29.2
|
|
|
3e8f86 |
|