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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux