From b631c74df57e9ea52f54b4d6be79b63bc89e5eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Thu, 18 Oct 2018 16:07:05 +0200 Subject: [PATCH] lszcrypt: Replace sprintf() with util_asprintf() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get rid of fixed buffers and avoid the following GCC8 compile warnings: lszcrypt.c: In function ‘main’: lszcrypt.c:642:28: warning: ‘%04x’ directive writing between 4 and 8 bytes into a region of size between 7 and 13 [-Wformat-overflow=] sprintf(sub_dev, "%02x.%04x", id, dom); ^~~~ lszcrypt.c:642:22: note: directive argument in the range [0, 2147483647] sprintf(sub_dev, "%02x.%04x", id, dom); ^~~~~~~~~~~ lszcrypt.c:642:5: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 16 sprintf(sub_dev, "%02x.%04x", id, dom); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- zconf/zcrypt/lszcrypt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zconf/zcrypt/lszcrypt.c b/zconf/zcrypt/lszcrypt.c index 580407fc..ae247f5c 100644 --- a/zconf/zcrypt/lszcrypt.c +++ b/zconf/zcrypt/lszcrypt.c @@ -12,6 +12,7 @@ #include "lib/util_base.h" #include "lib/util_file.h" +#include "lib/util_libc.h" #include "lib/util_opt.h" #include "lib/util_panic.h" #include "lib/util_path.h" @@ -620,7 +621,7 @@ static void show_devices_argv(char *argv[]) { struct util_rec *rec = util_rec_new_wide("-"); struct dirent **dev_vec, **subdev_vec; - char *ap, *grp_dev, *path, card[16], sub_dev[16]; + char *ap, *grp_dev, *path, *card, *sub_dev; int id, dom, i, n, dev_cnt, sub_cnt; /* check if ap driver is available */ @@ -639,14 +640,16 @@ static void show_devices_argv(char *argv[]) if (sscanf(argv[i], "%x.%x", &id, &dom) >= 1) { /* at least the id field was valid */ if (id >= 0 && dom >= 0) { /* single subdevice */ - sprintf(sub_dev, "%02x.%04x", id, dom); + util_asprintf(&sub_dev, "%02x.%04x", id, dom); grp_dev = util_path_sysfs("devices/ap/card%02x", id); show_subdevice(rec, grp_dev, sub_dev); free(grp_dev); + free(sub_dev); } else { /* group device */ - sprintf(card, "card%02x", id); + util_asprintf(&card, "card%02x", id); show_device(rec, card); + free(card); } return; }