From 8ddb6b0caee7eb8699aef7ccd67316d241448e7e Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 29 Sep 2011 14:56:41 -0400 Subject: include,xalloc: check for NULL before calling strdup This fixes a segfault in mount (and possibly elsewhere) when invoked without a -t parameter. Broken in 7ef9fd7 when the common xalloc.h libs were introduced. Signed-off-by: Dave Reisner --- include/xalloc.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'include/xalloc.h') diff --git a/include/xalloc.h b/include/xalloc.h index 8c505beed..bea7e3194 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -51,9 +51,14 @@ void *xcalloc(const size_t nelems, const size_t size) static inline char *xstrdup(const char *str) { - char *ret = strdup(str); + char *ret; - if (!ret && str) + if (!str) + return NULL; + + ret = strdup(str); + + if (!ret) err(XALLOC_EXIT_CODE, "cannot duplicate string"); return ret; } -- cgit v1.2.3-55-g7522