(backport) udev/net-id: check all snprintf return values
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 23 Feb 2018 10:12:19 +0000 (11:12 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Wed, 26 Feb 2020 10:39:00 +0000 (11:39 +0100)
commitde15a1bdad48788116c0e2588b67b4d4ac8bd3ab
tree1a6dda9553ff6b6a882b45768bdd25bb7fe8ad1e
parent56683ae9a81e61f2ac6e77d2d28de7b568522ac6
(backport) udev/net-id: check all snprintf return values

gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                                               ^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.

Change-Id: I52c289a5e4d660c999383ee628c596e00c30af21
src/basic/stdio-util.h
src/udev/udev-builtin-net_id.c