mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] xstrdup: don't panic on xstrdup(NULL)
Date: Fri,  9 Sep 2016 08:37:22 +0200	[thread overview]
Message-ID: <1473403042-20535-1-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20160909062541.s4pgmxefhgq7rlge@pengutronix.de>

Instead return just NULL. This matches the behaviour of kstrdup in the
kernel and xstrdup in busybox.

This fixes a panic with CONFIG_CMD_MAGICVAR=y and
CONFIG_CMD_MAGICVAR_HELP unset in magicvar_add() where description is
always NULL.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 lib/xfuncs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index aaf078854429..1dc2ea92d84f 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -56,10 +56,15 @@ EXPORT_SYMBOL(xzalloc);
 
 char *xstrdup(const char *s)
 {
-	char *p = strdup(s);
+	char *p;
+
+	if (!s)
+		return NULL;
 
+	p = strdup(s);
 	if (!p)
 		panic("ERROR: out of memory\n");
+
 	return p;
 }
 EXPORT_SYMBOL(xstrdup);
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-09-09  6:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 19:27 barebox crashes with CONFIG_CMD_MAGICVAR=y and CONFIG_CMD_MAGICVAR_HELP unset Uwe Kleine-König
2016-09-09  6:25 ` Sascha Hauer
2016-09-09  6:37   ` Uwe Kleine-König [this message]
2016-09-12  6:16     ` [PATCH] xstrdup: don't panic on xstrdup(NULL) Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473403042-20535-1-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox