mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usbutils.git
synced 2024-11-14 14:33:44 +08:00
sysfs.c: fix an theoretical issue with snprintf()
Again, code scanners really don't like C string functions, and warn about the potential for a buffer to possibly be too big for a snprintf() call as the checking wasn't quite correct. Fix the check for a buffer overflow up better and handle any potential issues that checking tools could come up with. No real functional change as the sysfs path should be just fine. And really, this is all just userspace code... Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
bb1e4b7dce
commit
59f1fe166f
8
sysfs.c
8
sysfs.c
@ -44,8 +44,12 @@ int get_sysfs_name(char *buf, size_t size, libusb_device *dev)
|
||||
}
|
||||
|
||||
len += snprintf(buf, size, "%d-", bnum);
|
||||
for (int i = 0; i < num_pnums; i++)
|
||||
len += snprintf(buf + len, size - len, i ? ".%d" : "%d", pnums[i]);
|
||||
for (int i = 0; i < num_pnums; i++) {
|
||||
int n = snprintf(buf + len, size - len, i ? ".%d" : "%d", pnums[i]);
|
||||
if ((n < 0) || (n >= (int)(size - len)))
|
||||
break;
|
||||
len += n;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user