Commit 960a734e authored by Dave Reisner's avatar Dave Reisner Committed by Karel Zak
Browse files

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 7ef9fd7c

 when the common xalloc.h libs were introduced.

Signed-off-by: default avatarDave Reisner <dreisner@archlinux.org>
parent 8c62239e
No related merge requests found
Showing with 7 additions and 2 deletions
......@@ -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;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment