[PATCH] lib: parameter: Do not modify pointer returned from xstrdup()

Sascha Hauer s.hauer at pengutronix.de
Thu Jun 16 06:47:30 PDT 2022


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 at 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




More information about the barebox mailing list