From 3a7c85d1dedb672ba19ea8958f18f5f7d0fe2321 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 21 Nov 2015 16:47:32 -0800 Subject: [PATCH] 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 --- lib/distribute.c | 12 ++++++++---- lib/if_rmap.c | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) 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); -- 2.39.5