xalloc: check for NULL before calling strdup
PATCH 1/2 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 <[email protected]>
--- include/xalloc.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
include/xalloc.h +7 -2
@@ -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; }
Signature · 1 line
1.7.6.4
PATCH 2/2 xalloc: fix whitespace to be consistent
We use spaces for the rest of this file, so the random tabs within xstrdup stand out.
Signed-off-by Dave Reisner <[email protected]>
--- include/xalloc.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
include/xalloc.h +7 -7
@@ -51,16 +51,16 @@ void *xcalloc(const size_t nelems, const size_t size)static inline char *xstrdup (const char *str) { -char *ret; +char *ret; -if (!str) -return NULL ; +if (!str) +return NULL ; - ret =strdup (str); + ret =strdup (str); -if (!ret) -err (XALLOC_EXIT_CODE ,"cannot duplicate string" ); -return ret; +if (!ret) +err (XALLOC_EXIT_CODE ,"cannot duplicate string" ); +return ret; }#endif
Signature · 1 line
1.7.6.4
Quoted 2 lines · Dave Reisner
include/xalloc.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
Applied, thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 2/2] xalloc: fix whitespace to be consistent
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
include/xalloc.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com