Skip to contentSkip to conversation

lib/kobject.c: Check parameter in kobject_get_path

PATCH In review yan 2 participants 2 messages Apr 21, 2012 – Apr 23, 2012

Subsystems (2)
lore
Share & tools
lore

yan

author
#0 lore raw

PATCH 1/4 lib/kobject.c: Check parameter in kobject_get_path

kobject_get_path is exported, it passes its parameter kobj to get_kobj_path_length and fill_kobj_path which are both static and called only once here. So check this parameter.

---
 lib/kobject.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
lib/kobject.c +3 -0
index 38fcc60..56c8cb3 100644
@@ -104,6 +104,9 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
 	char *path;
 	int len;
 
+	if (!kobj)
+		return NULL;
+
 	len = get_kobj_path_length(kobj);
 	if (len == 0)
 		return NULL;
Signature · 1 line
1.7.5.1
maintainer
#1 lore raw
Quoted 3 lines · yan

kobject_get_path is exported, it passes its parameter kobj to get_kobj_path_length and fill_kobj_path which are both static and called only once here. So check this parameter.

Why? If you call this function, you should pass in a valid pointer, that's the proper way to call it. No need to be "defensive" here at all, if the caller messes up, then it crashes, as it should not be making this type of call on a NULL pointer.

In looking at all of the in-kernel users of this function, they all do this properly, so I see no need for this patch.

And these types of patches are not "trivial" at all, so please don't mark them as such.

thanks,

greg k-h