From 3c80f7e025dbb0d0225a804a0424d7f0f35a628b Mon Sep 17 00:00:00 2001 From: Stefan Haberland Date: Fri, 22 Sep 2017 11:12:31 +0200 Subject: [PATCH] dasdinfo: fix buffer overflow warning Fix a possible buffer overflow. The buffer overflow is only theoretical since the device name is max 8 characters in length. This fixes following gcc 7 warning: dasdinfo.c: In function 'main': dasdinfo.c:576:33: warning: '%s' directive writing up to 255 bytes into a region of size 69 [-Wformat-overflow=] sprintf(*uidfile,"/sys/block/%s/device/uid", ^~ In file included from /usr/include/stdio.h:862:0, from dasdinfo.c:15: /usr/include/bits/stdio2.h:33:10: note: '__builtin___sprintf_chk' output between 23 and 278 bytes into a destination of size 80 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Stefan Haberland Signed-off-by: Michael Holzheu --- dasdinfo/dasdinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dasdinfo/dasdinfo.c b/dasdinfo/dasdinfo.c index 0506b5cf..c8bda3b9 100644 --- a/dasdinfo/dasdinfo.c +++ b/dasdinfo/dasdinfo.c @@ -573,8 +573,8 @@ static int dinfo_get_uid_from_devnode(char **uidfile, char *devnode) if (strncmp(stat_dev, readbuf, MAX(strlen(stat_dev), strlen(readbuf)-1)) == 0) { - sprintf(*uidfile,"/sys/block/%s/device/uid", - dir_entry->d_name); + snprintf(*uidfile, RD_BUFFER_SIZE, + "/sys/block/%s/device/uid", dir_entry->d_name); break; } }