summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2015-11-21 16:47:32 -0800
committerDonald Sharp <sharpd@cumulusnetworks.com>2015-11-23 13:31:04 -0800
commit3a7c85d1dedb672ba19ea8958f18f5f7d0fe2321 (patch)
treee9e41dd9996a9b5e98db00601eef2159d8faeb54
parent1a1f4efab365954c7b0ab56e974c2d707c0923c5 (diff)
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 <sharpd@cumulusnetworks.com>
-rw-r--r--lib/distribute.c12
-rw-r--r--lib/if_rmap.c9
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);