Skip to contentSkip to conversation

cmd_itest.c: fix pointer dereferencing

PATCH New Frans Meulenbroeks 1 participant 1 message Feb 19, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
common/cmd_itest.c +3 -1
index 5b301bf..d0ef747 100644
@@ -66,17 +66,23 @@ op_tbl_t op_table [] = {
 
 static long evalexp(char *s, int w)
 {
-	long l, *p;
+	long l = 0; /* default return value */
+	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);
}
-
return (l & ((1 << (w * 8)) - 1));
+
}

static char * evalstr(char *s)

Signature · 1 line
1.5.4.3