Skip to contentSkip to conversation

wimax: debug: fix a missing-check bug in d_parse_params()

PATCH In review Gen Zhang 2 participants 3 messages May 30, 2019 – Jun 5, 2019

lore
Share & tools
lore

Gen Zhang

author
#0 lore raw

PATCH 1/1 wimax: debug: fix a missing-check bug in d_parse_params()

In d_parse_params(), 'params_orig' is allocated by kstrdup(). It returns NULL when fails. So 'params_orig' should be checked.

---

include/linux/wimax/debug.h +5 -0
index aaf24ba..bacd6cb 100644
@@ -496,6 +496,11 @@ void d_parse_params(struct d_level *d_level, size_t d_level_size,
 	if (_params == NULL)
 		return;
 	params_orig = kstrdup(_params, GFP_KERNEL);
+	if (!params_orig) {
+		printk(KERN_ERR "%s: can't duplicate string '%s'\n",
+		       tag, _params);
+		return;
+	}
 	params = params_orig;
 	while (1) {
 		token = strsep(&params, " ");
#1 lore raw
Quoted 10 lines · Gen Zhang

In d_parse_params(), 'params_orig' is allocated by kstrdup(). It returns NULL when fails. So 'params_orig' should be checked.

---

include/linux/wimax/debug.h +0 -0
index aaf24ba..bacd6cb 100644

include/linux/wimax/debug.h void d_parse_params(struct d_level *d_level, size_t d_level_size, · line 501

Quoted 6 lines
include/linux/wimax/debug.h +3 -0
@@ -496,6 +496,11 @@ void d_parse_params(struct d_level *d_level, size_t d_level_size,
 	if (_params == NULL)
 		return;
 	params_orig = kstrdup(_params, GFP_KERNEL);
+	if (!params_orig) {
+		printk(KERN_ERR "%s: can't duplicate string '%s'\n",
+		       tag, _params);

We use pr_err these days.

thanks,

Signature · 2 lines
js
suse labs
author
#2 lore raw
Quoted 4 lines · Jiri Slaby
Quoted 3 lines · Gen Zhang

In d_parse_params(), 'params_orig' is allocated by kstrdup(). It returns NULL when fails. So 'params_orig' should be checked.

Quoted 15 lines

include/linux/wimax/debug.h void d_parse_params(struct d_level *d_level, size_t d_level_size, · line 501

Quoted 13 lines

---

include/linux/wimax/debug.h +3 -0
index aaf24ba..bacd6cb 100644
@@ -496,6 +496,11 @@ void d_parse_params(struct d_level *d_level, size_t d_level_size,
 	if (_params == NULL)
 		return;
 	params_orig = kstrdup(_params, GFP_KERNEL);
+	if (!params_orig) {
+		printk(KERN_ERR "%s: can't duplicate string '%s'\n",
+		       tag, _params);

We use pr_err these days.

Thanks for your reply. I used printk() because at least in this file, printk() is used.

Should I change printk() to pr_err() and revise this patch, or should all printk() in this file be changed? I hope you can give me some specific instructions. Actually I don't know what to do when getting this reply...

Thanks
Gen

Quoted 5 lines

thanks,

Signature · 2 lines
js
suse labs