From: Dave Reisner Date: Thu, 29 Sep 2011 18:56:41 +0000 (-0400) Subject: include,xalloc: check for NULL before calling strdup X-Git-Tag: v2.20.1~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=960a734e3b3232633fc1508bcd78f112ecc3efa0;p=thirdparty%2Futil-linux.git 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 --- diff --git a/include/xalloc.h b/include/xalloc.h index 8c505beed4..bea7e31941 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; }