util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] xalloc: check for NULL before calling strdup
@ 2011-09-29 18:56 Dave Reisner
  2011-09-29 18:56 ` [PATCH 2/2] xalloc: fix whitespace to be consistent Dave Reisner
  2011-09-29 23:42 ` [PATCH 1/2] xalloc: check for NULL before calling strdup Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Reisner @ 2011-09-29 18:56 UTC (permalink / raw)
  To: util-linux; +Cc: Dave Reisner

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 |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/xalloc.h b/include/xalloc.h
index 8c505be..bea7e31 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;
 }
-- 
1.7.6.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-29 23:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-29 18:56 [PATCH 1/2] xalloc: check for NULL before calling strdup Dave Reisner
2011-09-29 18:56 ` [PATCH 2/2] xalloc: fix whitespace to be consistent Dave Reisner
2011-09-29 23:42   ` Karel Zak
2011-09-29 23:42 ` [PATCH 1/2] xalloc: check for NULL before calling strdup Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).