diff options
author | Dave Reisner | 2011-09-29 20:56:41 +0200 |
---|---|---|
committer | Karel Zak | 2011-09-30 00:24:05 +0200 |
commit | 8ddb6b0caee7eb8699aef7ccd67316d241448e7e (patch) | |
tree | ff0514c5f56c902bba446768b6f31800963e8c95 /include/xalloc.h | |
parent | tests: add missing file (diff) | |
download | kernel-qcow2-util-linux-8ddb6b0caee7eb8699aef7ccd67316d241448e7e.tar.gz kernel-qcow2-util-linux-8ddb6b0caee7eb8699aef7ccd67316d241448e7e.tar.xz kernel-qcow2-util-linux-8ddb6b0caee7eb8699aef7ccd67316d241448e7e.zip |
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 <dreisner@archlinux.org>
Diffstat (limited to 'include/xalloc.h')
-rw-r--r-- | include/xalloc.h | 9 |
1 files changed, 7 insertions, 2 deletions
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; } |