Skip to contentSkip to conversation

printk: Don't read beyond string arguments' terminating zero

PATCH New Markus Armbruster 1 participant 1 message Apr 9, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: Don't read beyond string arguments' terminating zero

Fix add_preferred_console() and update_console_cmdline() not to to read beyond the terminating zero of their name argument.

---
 kernel/printk.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/printk.c +2 -2
index c46a20a..52526df 100644
@@ -865,7 +865,7 @@ int add_preferred_console(char *name, int idx, char *options)
 		return -E2BIG;
 	selected_console = i;
 	c = &console_cmdline[i];
-	memcpy(c->name, name, sizeof(c->name));
+	strlcpy(c->name, name, sizeof(c->name));
 	c->name[sizeof(c->name) - 1] = 0;
 	c->options = options;
 	c->index = idx;
@@ -881,7 +881,7 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha
 		if (strcmp(console_cmdline[i].name, name) == 0 &&
 			  console_cmdline[i].index == idx) {
 				c = &console_cmdline[i];
-				memcpy(c->name, name_new, sizeof(c->name));
+				strlcpy(c->name, name_new, sizeof(c->name));
 				c->name[sizeof(c->name) - 1] = 0;
 				c->options = options;
 				c->index = idx_new;
Signature · 1 line
1.5.3.3