Skip to contentSkip to conversation

cmd_itest.c: fix pointer dereferencing

PATCH New Frans Meulenbroeks 3 participants 3 messages Feb 22, 2010 – Feb 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 cmd_itest.c: fix pointer dereferencing

fix pointer dereferencing
if the size is .b and .w an 8 or 16 bit access is done.

---
 common/cmd_itest.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
common/cmd_itest.c +7 -2
index 5b301bf..58c5e7b 100644
@@ -66,12 +66,17 @@ op_tbl_t op_table [] = {
 
 static long evalexp(char *s, int w)
 {
-	long l, *p;
+	long l = 0;
+	long *p;
 
 	/* if the parameter starts with a * then assume is a pointer to the value we want */
 	if (s[0] == '*') {
 		p = (long *)simple_strtoul(&s[1], NULL, 16);
-		l = *p;
+		switch (w) {
+		case 1: return((long)(*(unsigned char *)p));
+		case 2: return((long)(*(unsigned short *)p));
+		case 4: return(*p);
+		}
 	} else {
 		l = simple_strtoul(s, NULL, 16);
 	}
Signature · 1 line
1.6.4.2
#1 lore raw

PATCH 2/2 cmd_itest.c: fix pointer dereferencing

Hi Frans,

Quoted 4 lines

fix pointer dereferencing
if the size is .b and .w an 8 or 16 bit access is done.

You could have included my previously given Acked-by. But anyway:

Quoted 28 lines
---
 common/cmd_itest.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
common/cmd_itest.c +7 -2
index 5b301bf..58c5e7b 100644
@@ -66,12 +66,17 @@ op_tbl_t op_table [] = {
 
 static long evalexp(char *s, int w)
 {
-	long l, *p;
+	long l = 0;
+	long *p;
 
 	/* if the parameter starts with a * then assume is a pointer to the value we want */
 	if (s[0] == '*') {
 		p = (long *)simple_strtoul(&s[1], NULL, 16);
-		l = *p;
+		switch (w) {
+		case 1: return((long)(*(unsigned char *)p));
+		case 2: return((long)(*(unsigned short *)p));
+		case 4: return(*p);
+		}
 	} else {
 		l = simple_strtoul(s, NULL, 16);
 	}
Signature · 7 lines
It's like manually inflatable airbags -- people will never
think to use it in time to actually get any help from it.
             -- Miles Bader in <[email protected]>
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#2 lore raw

PATCH 2/2 cmd_itest.c: fix pointer dereferencing

In reply to Frans Meulenbroeks

Dear Frans Meulenbroeks,

Quoted 7 lines · In message <[email protected]> you…

fix pointer dereferencing
if the size is .b and .w an 8 or 16 bit access is done.

---
 common/cmd_itest.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"We learn from history that we learn nothing from history."
- George Bernard Shaw