diff options
author | Bui Quang Minh <minhquangbui99@gmail.com> | 2021-03-31 21:40:58 +0700 |
---|---|---|
committer | Bui Quang Minh <minhquangbui99@gmail.com> | 2021-03-31 21:40:58 +0700 |
commit | 214125a6f10c2bf5af6f1866cfe0cd6002547827 (patch) | |
tree | d30d786363a83b85da940783e6a2f0fe0131e894 | |
parent | 1a3f8b662e3cce40768d45be3dd2c9fb93808065 (diff) | |
download | usbutils-214125a6f10c2bf5af6f1866cfe0cd6002547827.tar.gz |
lsusb-t: Add lower bound checks in read_sysfs_file_string
I have a USB device that returns "\n\n" in manufacturer field which
makes newline cleanup in read_sysfs_file_string result in out-of-bound
access.
Fix this by adding lower bound checks in the loops.
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
-rw-r--r-- | lsusb-t.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -241,11 +241,11 @@ static void read_sysfs_file_string(const char *d_name, const char *file, char *b if (r > 0 && r < len) { buf[r] = '\0'; r--; - while (buf[r] == '\n') { + while (r >= 0 && buf[r] == '\n') { buf[r] = '\0'; r--; } - while (r) { + while (r >= 0) { if (buf[r] == '\n') buf[r] = ' '; r--; |