mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Commit3c80f7e025("dasdinfo: fix buffer overflow warning") changed a sprintf call to snprintf to avoid a buffer overflow warning. However, GCC 7 now warns about a potential truncation with snprintf: dasdinfo.c: In function 'main': dasdinfo.c:577:18: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 69 [-Wformat-truncation=] "/sys/block/%s/device/uid", dir_entry->d_name); ^~ dasdinfo.c:576:4: note: 'snprintf' output between 23 and 278 bytes into a destination of size 80 snprintf(*uidfile, RD_BUFFER_SIZE, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "/sys/block/%s/device/uid", dir_entry->d_name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We could get around this by increasing the buffer. Though, the current buffer size is already plenty and we know better anyway. Avoid the warning by simply checking the return value of snprintf and display an error in case data was truncated nonetheless. Fixes:3c80f7e025("dasdinfo: fix buffer overflow warning") Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>