[PATCH v3 17/22] dyndbg: fix old BUG_ON in >control parser

Łukasz Bartosik posted 22 patches 2 years ago
There is a newer version of this series
[PATCH v3 17/22] dyndbg: fix old BUG_ON in >control parser
Posted by Łukasz Bartosik 2 years ago
From: Jim Cromie <jim.cromie@gmail.com>

Fix a BUG_ON from 2009.  I have hit it while fuzzing >control on some
other patches, and panic from user input is bad.  Replace the BUG_ON
with pr_error and return -EINVAL.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 8ce485fc84ff..d4e50e4f6635 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -650,7 +650,11 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
 		} else {
 			for (end = buf; *end && !isspace(*end); end++)
 				;
-			BUG_ON(end == buf);
+			if (end == buf) {
+				pr_err("parse err after word:%d=%s\n", nwords,
+				       nwords ? words[nwords - 1] : "<none>");
+				return -EINVAL;
+			}
 		}
 
 		/* `buf' is start of word, `end' is one past its end */
-- 
2.43.0.472.g3155946c3a-goog