From a0fe9be254b944f5b005dd4b36c414827bcb40df Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 16 May 2021 07:32:47 +0900 Subject: [PATCH] LU-14093 utils: fix format-overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix the following warning on gcc11 by making numbuf big enough to fit format content. lfs.c: In function ‘print_quota’: lfs.c:7719:48: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=] 7719 | sprintf(numbuf[0], "%s*", strbuf); | ^ lfs.c:7719:25: note: ‘sprintf’ output between 2 and 33 bytes into a destination of size 32 7719 | sprintf(numbuf[0], "%s*", strbuf); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test-parameters: trivial Change-Id: I021e6ffff2e1405eadbe689f718674af4d4d6376 Signed-off-by: Dominique Martinet Reviewed-on: https://review.whamcloud.com/43711 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Neil Brown --- lustre/utils/lfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index b32c6d1..9afbbc9 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -7944,7 +7944,7 @@ static void kbytes2str(__u64 num, char *buf, int buflen, bool h) } } -#define STRBUF_LEN 32 +#define STRBUF_LEN 24 static void print_quota(char *mnt, struct if_quotactl *qctl, int type, int rc, bool h, bool show_default) { @@ -7958,7 +7958,7 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type, qctl->qc_cmd == LUSTRE_Q_GETDEFAULT_POOL) { int bover = 0, iover = 0; struct obd_dqblk *dqb = &qctl->qc_dqblk; - char numbuf[3][STRBUF_LEN]; + char numbuf[3][STRBUF_LEN + 2]; /* 2 for brackets or wildcard */ char timebuf[40]; char strbuf[STRBUF_LEN]; -- 1.8.3.1