]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include,xalloc: check for NULL before calling strdup
authorDave Reisner <d@falconindy.com>
Thu, 29 Sep 2011 18:56:41 +0000 (14:56 -0400)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Sep 2011 22:24:05 +0000 (00:24 +0200)
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 <dreisner@archlinux.org>
include/xalloc.h

index 8c505beed45a7a8e13b3e9eb8fdfacf176ba4585..bea7e31941273b57981ff7ed7c0a613254536b91 100644 (file)
@@ -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;
 }