Skip to contentSkip to conversation

depmod: Fix writing over array length

PATCH In review Lucas De Marchi 2 participants 3 messages Jun 3, 2022 – Jun 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 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];
	      |                      ^~~~~
---
 tools/depmod.c | 1 +
 1 file changed, 1 insertion(+)
tools/depmod.c +1 -0
index 4117dd1..364b7d4 100644
@@ -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;
Signature · 1 line
2.36.1
#1 lore raw

PATCH 2/2 modprobe: re-use modname variable

---
 tools/modprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/modprobe.c +1 -1
index 830c667..a825fb5 100644
@@ -324,7 +324,7 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
 	const char *modname = kmod_module_get_name(mod);
 	int flags = 0, err;
 
-	SHOW("rmmod %s\n", kmod_module_get_name(mod));
+	SHOW("rmmod %s\n", modname);
 
 	if (dry_run)
 		return 0;
Signature · 1 line
2.36.1
#2 lore raw
In reply to Lucas De Marchi

These 2 patches are now applied.

Lucas De Marchi

Quoted 37 lines · Lucas De Marchi

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];
	      |                      ^~~~~

---
tools/depmod.c | 1 +

1 file changed, 1 insertion(+)
tools/depmod.c +1 -0
index 4117dd1..364b7d4 100644
@@ -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;
Signature · 1 line
2.36.1