public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] mtdparts: fix write through NULL pointer
@ 2010-04-28  9:00 Wolfgang Denk
  2010-04-28  9:00 ` [U-Boot] [PATCH 2/2] mtdparts: get rid of custom DEBUG macro, use debug() Wolfgang Denk
  2010-04-28 11:12 ` [U-Boot] [PATCH 1/2] mtdparts: fix write through NULL pointer Stefano Babic
  0 siblings, 2 replies; 6+ messages in thread
From: Wolfgang Denk @ 2010-04-28  9:00 UTC (permalink / raw)
  To: u-boot

The "mtdparts add" command wrote through a NULL pointer - on many
systems this went unnoticed (PowerPC has writable RAM there, some ARM
systems have ROM where a write has no effect), but on arm1136
(i.MX31) it crashed the system.

Add appropriate checks.

Signed-off-by: Wolfgang Denk <wd@denx.de>
---
 common/cmd_mtdparts.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 0b5f747..cec154c 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -837,14 +837,16 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	u32 offset;
 	int err = 1;
 
-	p = mtd_dev;
+	DEBUGF("===device_parse===\n");
+
+	assert(retdev);
 	*retdev = NULL;
-	*ret = NULL;
 
-	DEBUGF("===device_parse===\n");
+	if (ret)
+		*ret = NULL;
 
 	/* fetch <mtd-id> */
-	mtd_id = p;
+	mtd_id = p = mtd_dev;
 	if (!(p = strchr(mtd_id, ':'))) {
 		printf("no <mtd-id> identifier\n");
 		return 1;
@@ -913,12 +915,15 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
 	/* check for next device presence */
 	if (p) {
 		if (*p == ';') {
-			*ret = ++p;
+			if (ret)
+				*ret = ++p;
 		} else if (*p == '\0') {
-			*ret = p;
+			if (ret)
+				*ret = p;
 		} else {
 			printf("unexpected character '%c' at the end of device\n", *p);
-			*ret = NULL;
+			if (ret)
+				*ret = NULL;
 			return 1;
 		}
 	}
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-01 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-28  9:00 [U-Boot] [PATCH 1/2] mtdparts: fix write through NULL pointer Wolfgang Denk
2010-04-28  9:00 ` [U-Boot] [PATCH 2/2] mtdparts: get rid of custom DEBUG macro, use debug() Wolfgang Denk
2010-04-28 11:12 ` [U-Boot] [PATCH 1/2] mtdparts: fix write through NULL pointer Stefano Babic
2010-04-28 11:30   ` Stefan Roese
2010-04-30 22:39   ` Wolfgang Denk
2010-05-01 11:49     ` Stefano Babic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox