Avoid use of GNU-specific memmem().
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · Xen staging patchbot-unstable
# HG changeset patch
# User [email protected]
# Date 1167905854 0
# Node IDbdbfbfdfbd64ddedc775d55f1a9e842847fea7b2# Parent60f91c9f1a248491e2f216d009a27a4c7e5e67d4[XEN] Avoid use of GNU-specificmemmem().
xen/tools/symbols.c static void build_initial_tok_table(void · line 359
Quoted 10 lines
xen/tools/symbols.c +7
-0@@ -350,6 +350,14 @@ static void build_initial_tok_table(void table_cnt = pos; } +static void *memmem_pvt (void *h,size_t hlen,void *n,size_t nlen) +{ +char *p; +for (p = h; (p - (char *)h) <= (hlen - nlen); p++) +if (!memcmp (p, n, nlen))return p; +return NULL ; +}
size_t is unsigned, (hlen - nlen) can wrap and cause a segfault. The
patch below fixes it. Thanks,
Alex
---
xen/tools/symbols.c +1 -1
@@ -353,7 +353,7 @@ static void *memmem_pvt(void *h, size_tstatic void *memmem_pvt (void *h,size_t hlen,void *n,size_t nlen) {char *p; -for (p = h; (p - (char *)h) <= (hlen - nlen); p++) +for (p = h; (p - (char *)h) <= (long )(hlen - nlen); p++)if (!memcmp (p, n, nlen))return p;return NULL ; }
Hi Keir,
Below is an alternative patch that perhaps more clearly illustrates
the problem with this memmem() replacement. This segfault occurs when parsing the nm output on ia64. Thanks,
Alex
Quoted 34 lines · Alex Williamson
Quoted 10 lines · Xen staging patchbot-unstable
# HG changeset patch
# User [email protected]
# Date 1167905854 0
# Node IDbdbfbfdfbd64ddedc775d55f1a9e842847fea7b2# Parent60f91c9f1a248491e2f216d009a27a4c7e5e67d4[XEN] Avoid use of GNU-specificmemmem().xen/tools/symbols.c static void build_initial_tok_table(void · line 359
Quoted 10 lines
xen/tools/symbols.c +7
-0@@ -350,6 +350,14 @@ static void build_initial_tok_table(void table_cnt = pos; } +static void *memmem_pvt (void *h,size_t hlen,void *n,size_t nlen) +{ +char *p; +for (p = h; (p - (char *)h) <= (hlen - nlen); p++) +if (!memcmp (p, n, nlen))return p; +return NULL ; +}
size_tis unsigned, (hlen - nlen) can wrap and cause a segfault. The
patch below fixes it. Thanks,Alex
Signed-off-by Alex Williamson <[email protected]>---
diff -r
a8930b548048xen/tools/symbols.c
xen/tools/symbols.c static void *memmem_pvt(void *h, size_t · line 359
Quoted 8 lines
xen/tools/symbols.c +1
-1@@ -353,7 +353,7 @@ static void *memmem_pvt(void *h, size_tstatic void *memmem_pvt (void *h,size_t hlen,void *n,size_t nlen) {char *p; -for (p = h; (p - (char *)h) <= (hlen - nlen); p++) +for (p = h; (p - (char *)h) <= (long )(hlen - nlen); p++)if (!memcmp (p, n, nlen))return p;return NULL ; }
---
xen/tools/symbols.c +2 -0
@@ -353,6 +353,8 @@ static void *memmem_pvt(void *h, size_tstatic void *memmem_pvt (void *h,size_t hlen,void *n,size_t nlen) {char *p; +if (nlen > hlen) +return NULL ;for (p = h; (p - (char *)h) <= (hlen - nlen); p++)if (!memcmp (p, n, nlen))return p;return NULL ;