PATCH -- kobject_set_name() doesn't allocate enough space
Subsystems (2)
Hi All,
The sapce allocated in kobject_set_name() is 1 byte less than it should be. The Attached patch fixes this bug.
Comments are welcome.
Thanks,
Linda Xie
IBM Linux Technology Center
lib/kobject.c +2 -2
@@ -344,12 +344,12 @@/* * 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. */
Quoted 3 lines · Linda Xie
The sapce allocated in
kobject_set_name()is 1 byte less than it should be. The Attached patch fixes this bug.
Good catch - it _should_ mean that long names always had the last byte cut off. Why didn't anybody notice? Are people just not using long names?
Quoted 1 line
Comments are welcome.
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
Quoted 7 lines · Linus Torvalds
The patch looks correct, but you should change the last test to be appropriate too, ie the
/* Still? Give up. */ if (need > limit) {
Quoted 7 lines
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:
lib/kobject.c Tue Dec 16 17:10:16 2003 +3 -3
@@ -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;