diff mbox series

[2/2] Regression: fix detecting selection

Message ID 20200415123138.17661-2-sbabic@denx.de
State Accepted
Headers show
Series [1/2] Fix regression by introducing strlcpy | expand

Commit Message

Stefano Babic April 15, 2020, 12:31 p.m. UTC
This was detected after introducing strlcpy(). The seeltion string is
copied without null terminating causing a wronf seletion to be taken.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/swupdate.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 67e9b9d..1dc2053 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -406,17 +406,14 @@  static int install_from_file(char *fname, int check)
 static int parse_image_selector(const char *selector, struct swupdate_cfg *sw)
 {
 	char *pos;
-	size_t len;
 
 	pos = strchr(selector, ',');
 	if (pos == NULL)
 		return -EINVAL;
 
-	len = pos - selector;
-	if (len > sizeof(sw->software_set))
-		len = sizeof(sw->software_set);
+	*pos = '\0';
 
-	strlcpy(sw->software_set, selector, len);
+	strlcpy(sw->software_set, selector, sizeof(sw->software_set));
 	/* pos + 1 will either be NULL or valid text */
 	strlcpy(sw->running_mode, pos + 1, sizeof(sw->running_mode));