public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PATCH -- kobject_set_name() doesn't allocate enough space
@ 2003-12-16 20:15 Linda Xie
  2003-12-16 20:44 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Linda Xie @ 2003-12-16 20:15 UTC (permalink / raw)
  To: linux-kernel, Greg KH; +Cc: scheel, wortman


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



diff -Nru a/lib/kobject.c b/lib/kobject.c
--- a/lib/kobject.c	Sun Dec 14 21:19:29 2003
+++ b/lib/kobject.c	Sun Dec 14 21:19:29 2003
@@ -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. */


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH -- kobject_set_name() doesn't allocate enough space
  2003-12-16 20:15 PATCH -- kobject_set_name() doesn't allocate enough space Linda Xie
@ 2003-12-16 20:44 ` Linus Torvalds
  2003-12-16 23:24   ` Linda Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2003-12-16 20:44 UTC (permalink / raw)
  To: Linda Xie; +Cc: linux-kernel, Greg KH, scheel, wortman



On Tue, 16 Dec 2003, Linda Xie wrote:
>
> 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?

> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH -- kobject_set_name() doesn't allocate enough space
  2003-12-16 20:44 ` Linus Torvalds
@ 2003-12-16 23:24   ` Linda Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Linda Xie @ 2003-12-16 23:24 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Linda Xie, linux-kernel, Greg KH, scheel, wortman

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;






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-16 23:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-16 20:15 PATCH -- kobject_set_name() doesn't allocate enough space Linda Xie
2003-12-16 20:44 ` Linus Torvalds
2003-12-16 23:24   ` Linda Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox