Skip to content

Commit a56c43b

Browse files
jbeichzeising
authored andcommitted
Explicitly truncate snprintf arguments for GCC 8+
udev-device.c: In function 'udev_device_new_from_devnum': udev-device.c:100:23: error: '.PCI_ID' directive output may be truncated writing 7 bytes into a region of size between 1 and 32 [-Werror=format-truncation=] 100 | snprintf(buf, 32, "%s.PCI_ID", devbuf); | ^~~~~~~ udev-device.c:100:2: note: 'snprintf' output between 8 and 39 bytes into a destination of size 32 100 | snprintf(buf, 32, "%s.PCI_ID", devbuf); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ udev-device.c:93:2: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] 93 | strncpy(devbuf, devpath + 1, 32); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ udev-utils.c: In function 'set_parent': udev-utils.c:501:34: error: '%s' directive output may be truncated writing up to 79 bytes into a region of size 28 [-Werror=format-truncation=] 501 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%desc", devname, unit); | ^~ ~~~~~~~ udev-utils.c:501:2: note: 'snprintf' output 12 or more bytes (assuming 91) into a destination of size 32 501 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%desc", devname, unit); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ udev-utils.c:507:34: error: '%s' directive output may be truncated writing up to 79 bytes into a region of size 28 [-Werror=format-truncation=] 507 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%pnpinfo", devname, unit); | ^~ ~~~~~~~ udev-utils.c:507:2: note: 'snprintf' output 15 or more bytes (assuming 94) into a destination of size 32 507 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%pnpinfo", devname, unit); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ udev-utils.c:512:34: error: '%s' directive output may be truncated writing up to 79 bytes into a region of size 28 [-Werror=format-truncation=] 512 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%parent", devname, unit); | ^~ ~~~~~~~ udev-utils.c:512:2: note: 'snprintf' output 14 or more bytes (assuming 93) into a destination of size 32 512 | snprintf(mib, sizeof(mib), "dev.%s.%s.%%parent", devname, unit); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 parent 778cd58 commit a56c43b

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

udev-device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
9090

9191
TRC("(%d) -> %s", (int)devnum, devpath);
9292
syspath = get_syspath_by_devpath(devpath);
93-
strncpy(devbuf, devpath + 1, 32);
93+
strncpy(devbuf, devpath + 1, 31);
9494
devbufptr = devbuf;
9595
devbufptr = strchrnul(devbufptr, '/');
9696
while (*devbufptr != '\0') {
9797
*devbufptr = '.';
9898
devbufptr = strchrnul(devbufptr, '/');
9999
}
100-
snprintf(buf, 32, "%s.PCI_ID", devbuf);
100+
snprintf(buf, 32, "%.24s.PCI_ID", devbuf);
101101
buflen = 32;
102102

103103
sysctlbyname(buf, devbuf, &buflen, NULL, 0);

udev-utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,18 +512,18 @@ set_parent(struct udev_device *ud)
512512
snprintf(devname, len + 1, "%s", sysname);
513513
unit = sysname + len;
514514

515-
snprintf(mib, sizeof(mib), "dev.%s.%s.%%desc", devname, unit);
515+
snprintf(mib, sizeof(mib), "dev.%.17s.%.3s.%%desc", devname, unit);
516516
len = sizeof(name);
517517
if (sysctlbyname(mib, name, &len, NULL, 0) < 0)
518518
return;
519519
*(strchrnul(name, ',')) = '\0'; /* strip name */
520520

521-
snprintf(mib, sizeof(mib), "dev.%s.%s.%%pnpinfo", devname, unit);
521+
snprintf(mib, sizeof(mib), "dev.%.14s.%.3s.%%pnpinfo", devname, unit);
522522
len = sizeof(pnpinfo);
523523
if (sysctlbyname(mib, pnpinfo, &len, NULL, 0) < 0)
524524
return;
525525

526-
snprintf(mib, sizeof(mib), "dev.%s.%s.%%parent", devname, unit);
526+
snprintf(mib, sizeof(mib), "dev.%.15s.%.3s.%%parent", devname, unit);
527527
len = sizeof(parentname);
528528
if (sysctlbyname(mib, parentname, &len, NULL, 0) < 0)
529529
return;

0 commit comments

Comments
 (0)