Skip to contentSkip to conversation

drivers/base/auxiliary: check return value of strrchr()

PATCH In review Li Zhong 2 participants 2 messages Sep 4, 2022

Subsystems (2)
lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH v2 1/1 drivers/base/auxiliary: check return value of strrchr()

The return value of strrchr() could be NULL, which will cause invalid offset in (int)(p - name). So we check it here.

---
 drivers/base/auxiliary.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/base/auxiliary.c +2 -0
index 8c5e65930617..2ec0306bfba3 100644
@@ -191,6 +191,8 @@ static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 	name = dev_name(dev);
 	p = strrchr(name, '.');
+	if (!p)
+		return -EINVAL;
 
 	return add_uevent_var(env, "MODALIAS=%s%.*s", AUXILIARY_MODULE_PREFIX,
 			      (int)(p - name), name);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 13 lines · Li Zhong

The return value of strrchr() could be NULL, which will cause invalid offset in (int)(p - name). So we check it here.

---
 drivers/base/auxiliary.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/base/auxiliary.c +0 -0
index 8c5e65930617..2ec0306bfba3 100644

drivers/base/auxiliary.c static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env) · line 195

Quoted 5 lines
drivers/base/auxiliary.c +2 -0
@@ -191,6 +191,8 @@ static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 	name = dev_name(dev);
 	p = strrchr(name, '.');
+	if (!p)
+		return -EINVAL;

How can that ever happen? For what device will that be triggered?

And again, please follow Documentation/process/researcher-guidelines.rst