From: Lucas De Marchi Date: Fri, 3 Jun 2022 20:49:01 +0000 (-0700) Subject: depmod: Fix writing over array length X-Git-Tag: v30~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07bf5e1520ebf520a65f350a99d6a7f28c482ab5;p=thirdparty%2Fkmod.git depmod: Fix writing over array length Make sure return value in flush_stream_to() is the length written if the value didn't the size. Fix warning on gcc 12.1: tools/depmod.c: In function ‘output_builtin_alias_bin’: tools/depmod.c:2465:24: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds] 2465 | modname[len] = '\0'; | ~~~~~~~^~~~~ tools/depmod.c:2460:22: note: while referencing ‘modname’ 2460 | char modname[PATH_MAX]; | ^~~~~~~ tools/depmod.c:2477:22: warning: array subscript 4096 is above array bounds of ‘char[4096]’ [-Warray-bounds] 2477 | value[len] = '\0'; | ~~~~~^~~~~ tools/depmod.c:2461:22: note: while referencing ‘value’ 2461 | char value[PATH_MAX]; | ^~~~~ Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 4117dd19..364b7d4f 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -2430,6 +2430,7 @@ static int flush_stream_to(FILE *in, int endchar, char *dst, size_t dst_sz) if (i == dst_sz) { WRN("Could not flush stream: %d. Partial content: %.*s\n", ENOSPC, (int) dst_sz, dst); + i--; } return c == endchar ? i : 0;