mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] lib: parameter: Do not modify pointer returned from xstrdup()
Date: Thu, 16 Jun 2022 15:47:30 +0200	[thread overview]
Message-ID: <20220616134730.2023501-1-s.hauer@pengutronix.de> (raw)

The sequence

value_new = xstrdup(val);
value_new = strim(value_new)

is buggy because we not free the pointer we originally allocated. Fix
this by skipping the leading whitespaces from the original string.
The bug itself never triggered because the string is never freed. That
will be fixed in the next patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/parameter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index adc3c7cdea..2c9da870a4 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -258,8 +258,8 @@ static int param_string_set(struct device_d *dev, struct param_d *p, const char
 	if (!val)
 		val = "";
 
-	value_new = xstrdup(val);
-	value_new = strim(value_new);
+	value_new = xstrdup(skip_spaces(val));
+	strim(value_new);
 	*ps->value = value_new;
 
 	if (!ps->set)
-- 
2.30.2




                 reply	other threads:[~2022-06-16 13:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220616134730.2023501-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH] lib: parameter: Do not modify pointer returned from xstrdup()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox