Skip to contentSkip to conversation

bootconfig: Initialize ret in xbc_parse_tree()

PATCH New Steven Rostedt 1 participant 1 message Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bootconfig: Initialize ret in xbc_parse_tree()

From: "Steven Rostedt (VMware)" <[email protected]>

The do while loop continues while ret is zero, but ret is never initialized. The check for ret in the loop at the while should always be initialized, but if an empty string were to be passed in, q would be NULL and p would be '\0', and it would break out of the loop without ever setting ret.

Set ret to zero, and then xbc_verify_tree() would be called and catch that it is an empty tree and report the proper error.

Fixes bdac5c2b243f ("bootconfig: Allocate xbc_data inside xbc_init()")

---
Changes since v1:
https://lkml.kernel.org/r/[email protected]
- Just updated the Fixes tag and removed Cc to stable

 lib/bootconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bootconfig.c +1 -1
index a10ab25f6fcc..70e0d52ffd24 100644
@@ -836,7 +836,7 @@ static int __init xbc_verify_tree(void)
 static int __init xbc_parse_tree(void)
 {
 	char *p, *q;
-	int ret, c;
+	int ret = 0, c;
 
 	last_parent = NULL;
 	p = xbc_data;
Signature · 1 line
2.31.1