Skip to contentSkip to conversation

dyndbg: fix use before null check

PATCH Superseded Jim Cromie 1 participant 1 message Dec 9, 2020

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jim Cromie

author maintainer
#0 lore raw

PATCH v2 1/1 dyndbg: fix use before null check

In commit a2d375eda771 ("dyndbg: refine export, rename to dynamic_debug_exec_queries()"), a string is copied before checking it isn't NULL. Fix this, report a usage/interface error, and return the proper error code.

Fixes a2d375eda771 ("dyndbg: refine export, rename to dynamic_debug_exec_queries()")

--
-v2 drop comment tweak, improve commit message

---
 lib/dynamic_debug.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/dynamic_debug.c +7 -2
index bd7b3aaa93c3..c70d6347afa2 100644
@@ -561,9 +561,14 @@ static int ddebug_exec_queries(char *query, const char *modname)
 int dynamic_debug_exec_queries(const char *query, const char *modname)
 {
 	int rc;
-	char *qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL);
+	char *qry; /* writable copy of query */
 
-	if (!query)
+	if (!query) {
+		pr_err("non-null query/command string expected\n");
+		return -EINVAL;
+	}
+	qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL);
+	if (!qry)
 		return -ENOMEM;
 
 	rc = ddebug_exec_queries(qry, modname);
Signature · 1 line
2.29.2