From: Donald Sharp Date: Sun, 22 Nov 2015 00:47:32 +0000 (-0800) Subject: lib: Fixup of NULL calls to XSTRDUP X-Git-Tag: frr-2.0-rc1~1186 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=3a7c85d1dedb672ba19ea8958f18f5f7d0fe2321;p=mirror%2Ffrr.git lib: Fixup of NULL calls to XSTRDUP There are a few situations where XSTRDUP can be called with a NULL This fix makes this impossible to happen Ticket: CM-8039 Reviewed-by: CCR-3849 Testing: Rip no longer crashes Signed-off-by: Donald Sharp --- diff --git a/lib/distribute.c b/lib/distribute.c index 525177e17b..fdd028d813 100644 --- a/lib/distribute.c +++ b/lib/distribute.c @@ -69,10 +69,12 @@ distribute_lookup (const char *ifname) struct distribute *dist; /* temporary reference */ - key.ifname = XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname); + key.ifname = (ifname) ? XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname) : NULL; dist = hash_lookup (disthash, &key); - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + + if (key.ifname) + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); return dist; } @@ -110,11 +112,13 @@ distribute_get (const char *ifname) struct distribute *ret; /* temporary reference */ - key.ifname = XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname); + key.ifname = (ifname) ? XSTRDUP(MTYPE_DISTRIBUTE_IFNAME, ifname) : NULL; ret = hash_get (disthash, &key, (void * (*) (void *))distribute_hash_alloc); - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + if (key.ifname) + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + return ret; } diff --git a/lib/if_rmap.c b/lib/if_rmap.c index 26a6d8c55b..f2d76c69d6 100644 --- a/lib/if_rmap.c +++ b/lib/if_rmap.c @@ -64,11 +64,13 @@ if_rmap_lookup (const char *ifname) struct if_rmap *if_rmap; /* temporary copy */ - key.ifname = XSTRDUP (MTYPE_IF_RMAP_NAME, ifname); + key.ifname = (ifname) ? XSTRDUP (MTYPE_IF_RMAP_NAME, ifname) : NULL; if_rmap = hash_lookup (ifrmaphash, &key); - XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + if (key.ifname) + XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + return if_rmap; } @@ -103,9 +105,10 @@ if_rmap_get (const char *ifname) struct if_rmap *ret; /* temporary copy */ - key.ifname = XSTRDUP (MTYPE_IF_RMAP_NAME, ifname); + key.ifname = (ifname) ? XSTRDUP (MTYPE_IF_RMAP_NAME, ifname) : NULL; ret = hash_get (ifrmaphash, &key, if_rmap_hash_alloc); + if (key.ifname) XFREE(MTYPE_IF_RMAP_NAME, key.ifname);