Skip to contentSkip to conversation

kgdb: strlen() doesn't count the terminator

PATCH In review Dan Carpenter 2 participants 2 messages Dec 9, 2010 – Dec 14, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kgdb: strlen() doesn't count the terminator

This is an off by one because strlen() doesn't count the null terminator. We strcpy() these strings into an array of size MAX_CONFIG_LEN.

drivers/misc/kgdbts.c +1 -1
index 59c118c..27dc463 100644
@@ -988,7 +988,7 @@ static void kgdbts_run_tests(void)
 
 static int kgdbts_option_setup(char *opt)
 {
-	if (strlen(opt) > MAX_CONFIG_LEN) {
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
 		printk(KERN_ERR "kgdbts: config string too long\n");
 		return -ENOSPC;
 	}
drivers/serial/kgdboc.c +1 -1
index 3374618..ec1748b 100644
@@ -130,7 +130,7 @@ static void kgdboc_unregister_kbd(void)
 
 static int kgdboc_option_setup(char *opt)
 {
-	if (strlen(opt) > MAX_CONFIG_LEN) {
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
 		printk(KERN_ERR "kgdboc: config string too long\n");
 		return -ENOSPC;
 	}
maintainer
#1 lore raw
Quoted 4 lines · Dan Carpenter

This is an off by one because strlen() doesn't count the null terminator. We strcpy() these strings into an array of size MAX_CONFIG_LEN.

I'll queue this patch for the 2.6.38 merge window since it is not something you can exploit without root access, and the fact that the vast majority of configurations do not include the kgdb test suite at all.

Thanks,
Jason.

Quoted 28 lines
drivers/misc/kgdbts.c +1 -1
index 59c118c..27dc463 100644
@@ -988,7 +988,7 @@ static void kgdbts_run_tests(void)
 
 static int kgdbts_option_setup(char *opt)
 {
-	if (strlen(opt) > MAX_CONFIG_LEN) {
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
 		printk(KERN_ERR "kgdbts: config string too long\n");
 		return -ENOSPC;
 	}
drivers/serial/kgdboc.c +1 -1
index 3374618..ec1748b 100644
@@ -130,7 +130,7 @@ static void kgdboc_unregister_kbd(void)
 
 static int kgdboc_option_setup(char *opt)
 {
-	if (strlen(opt) > MAX_CONFIG_LEN) {
+	if (strlen(opt) >= MAX_CONFIG_LEN) {
 		printk(KERN_ERR "kgdboc: config string too long\n");
 		return -ENOSPC;
 	}