mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: barebox crashes with CONFIG_CMD_MAGICVAR=y and CONFIG_CMD_MAGICVAR_HELP unset
Date: Fri, 9 Sep 2016 08:25:41 +0200	[thread overview]
Message-ID: <20160909062541.s4pgmxefhgq7rlge@pengutronix.de> (raw)
In-Reply-To: <20160908192752.dshheqp2qntzmon6@pengutronix.de>

On Thu, Sep 08, 2016 at 09:27:52PM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> with
> 
> 	CONFIG_CMD_MAGICVAR=y
> 	# CONFIG_CMD_MAGICVAR_HELP is not set
> 
> calling magicvar results in
> 
> 	md->description = xstrdup(description)
> 
> in line 64 of commands/magicvar.c. As CONFIG_CMD_MAGICVAR_HELP is not
> set, description is NULL which makes xstrdup fail.
> 
> I fixed it here doing
> 
> -       md->description = xstrdup(description);
> +       md->description = description ? xstrdup(description) : NULL;
> 
> but I can imagine other variants:
> 
> 	if (IS_ENABLED(CONFIG_CMD_MAGICVAR_HELP))
> 		md->description = xstrdup(description);
> 
> or fixing xstrdup to not choke on NULL.
> 
> What do you prefer?

kstrdup in the kernel tests for NULL and xstrdup in busybox does also.
Let's just add the test.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 19:27 Uwe Kleine-König
2016-09-09  6:25 ` Sascha Hauer [this message]
2016-09-09  6:37   ` [PATCH] xstrdup: don't panic on xstrdup(NULL) Uwe Kleine-König
2016-09-12  6:16     ` 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=20160909062541.s4pgmxefhgq7rlge@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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