Re: PATCH -- kobject_set_name() doesn't allocate enough space

From: Linda Xie
Date: Tue Dec 16 2003 - 18:21:49 EST


Linus Torvalds wrote:


The patch looks correct, but you should change the last test to be
appropriate too, ie the

/* Still? Give up. */
if (need > limit) {

test should, as far as I can tell, be

if (need >= limit) {

instead.

Linus

Hi Linus,

Thank you for pointing that out. Here is the updated patch:

diff -Nru a/lib/kobject.c b/lib/kobject.c
--- a/lib/kobject.c Tue Dec 16 17:10:16 2003
+++ b/lib/kobject.c Tue Dec 16 17:10:16 2003
@@ -344,16 +344,16 @@
/*
* Need more space? Allocate it and try again
*/
- name = kmalloc(need,GFP_KERNEL);
+ limit = need + 1;
+ name = kmalloc(limit,GFP_KERNEL);
if (!name) {
error = -ENOMEM;
goto Done;
}
- limit = need;
need = vsnprintf(name,limit,fmt,args);

/* Still? Give up. */
- if (need > limit) {
+ if (need >= limit) {
kfree(name);
error = -EFAULT;
goto Done;





-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/