From: Joe Hershberger Date: Mon, 11 May 2015 18:53:13 +0000 (-0500) Subject: Use map_sysmem when accessing memory in setexpr X-Git-Tag: v2025.01-rc5-pxa1908~12997 X-Git-Url: http://git.dujemihanovic.xyz/repo?a=commitdiff_plain;h=2068cea1731c7ec22a37acc0942357bf3b389001;p=u-boot.git Use map_sysmem when accessing memory in setexpr The setexpr command used to segfault when accessing memory in sandbox. The pointer accesses should be mapped. Signed-off-by: Joe Hershberger Cc: Simon Glass Reviewed-by: Simon Glass --- diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c index 926339b9f1..e7194fc4f4 100644 --- a/common/cmd_setexpr.c +++ b/common/cmd_setexpr.c @@ -12,23 +12,37 @@ #include #include #include +#include static ulong get_arg(char *s, int w) { - ulong *p; - /* - * if the parameter starts with a '*' then assume - * it is a pointer to the value we want + * If the parameter starts with a '*' then assume it is a pointer to + * the value we want. */ - if (s[0] == '*') { - p = (ulong *)simple_strtoul(&s[1], NULL, 16); + ulong *p; + ulong addr; + ulong val; + + addr = simple_strtoul(&s[1], NULL, 16); switch (w) { - case 1: return((ulong)(*(uchar *)p)); - case 2: return((ulong)(*(ushort *)p)); + case 1: + p = map_sysmem(addr, sizeof(uchar)); + val = (ulong)*(uchar *)p; + unmap_sysmem(p); + return val; + case 2: + p = map_sysmem(addr, sizeof(ushort)); + val = (ulong)*(ushort *)p; + unmap_sysmem(p); + return val; case 4: - default: return(*p); + default: + p = map_sysmem(addr, sizeof(ulong)); + val = *p; + unmap_sysmem(p); + return val; } } else { return simple_strtoul(s, NULL, 16);