Skip to contentSkip to conversation

cmd_nand: fix crashing bug in nand read/write

PATCH New Steve Sakoman 2 participants 2 messages Jun 7, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd_nand: fix crashing bug in nand read/write

Commit 418396e212b59bf907dbccad997ff50f7eb61b16 introduced a bug that causes nand read and nand write to crash in strcmp due to a null pointer.

Root cause is that strchr(cmd, '.') returns a null pointer when the input string does not contain a '.'

The strcmp function does not check for null pointers, resulting in a crash.

---
 common/cmd_nand.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
common/cmd_nand.c +1 -1
index fa44295..a91ccf4 100644
@@ -617,7 +617,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 
 		s = strchr(cmd, '.');
 
-		if (!strcmp(s, ".raw")) {
+		if (s && !strcmp(s, ".raw")) {
 			raw = 1;
 
 			if (arg_off(argv[3], &dev, &off, &size))
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 cmd_nand: fix crashing bug in nand read/write

Quoted 11 lines · Steve Sakoman

Commit 418396e212b59bf907dbccad997ff50f7eb61b16 introduced a bug that causes nand read and nand write to crash in strcmp due to a null pointer.

Root cause is that strchr(cmd, '.') returns a null pointer when the input string does not contain a '.'

The strcmp function does not check for null pointers, resulting in a crash.

Applied to u-boot-nand-flash, thanks!

This was missed in testing because U-Boot on PowerPC unfortunately has a valid mapping at NULL.

-Scott