Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH,Hurd] Fix deallocation after proc_getprocinfo call
@ 2014-11-02 15:26 Samuel Thibault
  2014-11-23  7:44 ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Samuel Thibault @ 2014-11-02 15:26 UTC (permalink / raw)
  To: bug-hurd, thomas, gdb-patches

2014-10-02  Samuel Thibault  <samuel.thibault@ens-lyon.org>

	* gdb/gnu-nat.c (inf_validate_procinfo): Multiply the number of
	elements pi_len by the size of the elements before calling
	vm_deallocate.
        (inf_validate_task_sc): Likewise, and properly deallocate the
        noise array.

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index d17a750..c571190 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -804,7 +804,7 @@ inf_validate_procinfo (struct inf *inf)
       inf->nomsg = !!(pi->state & PI_NOMSG);
       if (inf->nomsg)
 	inf->traced = !!(pi->state & PI_TRACED);
-      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));
       if (noise_len > 0)
 	vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
     }
@@ -844,9 +844,9 @@ inf_validate_task_sc (struct inf *inf)
 
   suspend_count = pi->taskinfo.suspend_count;
 
-  vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+  vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));
   if (noise_len > 0)
-    vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+    vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
 
   if (inf->task->cur_sc < suspend_count)
     {


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

* Re: [PATCH,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-02 15:26 [PATCH,Hurd] Fix deallocation after proc_getprocinfo call Samuel Thibault
@ 2014-11-23  7:44 ` Joel Brobecker
  2014-11-23  9:13   ` Samuel Thibault
  2014-11-23 15:19   ` [PATCHv2,Hurd] " Samuel Thibault
  0 siblings, 2 replies; 7+ messages in thread
From: Joel Brobecker @ 2014-11-23  7:44 UTC (permalink / raw)
  To: bug-hurd, thomas, gdb-patches

Hello Samuel,

On Sun, Nov 02, 2014 at 04:25:37PM +0100, Samuel Thibault wrote:
> 2014-10-02  Samuel Thibault  <samuel.thibault@ens-lyon.org>
> 
> 	* gdb/gnu-nat.c (inf_validate_procinfo): Multiply the number of
> 	elements pi_len by the size of the elements before calling
> 	vm_deallocate.
>         (inf_validate_task_sc): Likewise, and properly deallocate the
>         noise array.

Again, sorry about the late review...

I only have a few minor comments, almost trivial in nature. In
the ChangeLog entry above, watch out that the last 2 lines are
indented using spaces intead of tabs.

> diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
> index d17a750..c571190 100644
> --- a/gdb/gnu-nat.c
> +++ b/gdb/gnu-nat.c
> @@ -804,7 +804,7 @@ inf_validate_procinfo (struct inf *inf)
>        inf->nomsg = !!(pi->state & PI_NOMSG);
>        if (inf->nomsg)
>  	inf->traced = !!(pi->state & PI_TRACED);
> -      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
> +      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));

The line is too long (soft limit is 74 characters, hard limit is 80).
Suggest using "sizeof (struct procinfo)", which I think is better
than dereferencing a NULL pointer. This is based on guessing that
type procinfo_t is a pointer to struct procinfo, as suggested by
the code in inf_validate_procinfo.

>        if (noise_len > 0)
>  	vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
>      }
> @@ -844,9 +844,9 @@ inf_validate_task_sc (struct inf *inf)
>  
>    suspend_count = pi->taskinfo.suspend_count;
>  
> -  vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
> +  vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));

Same as above.

>    if (noise_len > 0)
> -    vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
> +    vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
>  
>    if (inf->task->cur_sc < suspend_count)
>      {

Thank you,
-- 
Joel


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

* Re: [PATCH,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-23  7:44 ` Joel Brobecker
@ 2014-11-23  9:13   ` Samuel Thibault
  2014-11-23  9:56     ` Joel Brobecker
  2014-11-23 15:19   ` [PATCHv2,Hurd] " Samuel Thibault
  1 sibling, 1 reply; 7+ messages in thread
From: Samuel Thibault @ 2014-11-23  9:13 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: bug-hurd, thomas, gdb-patches

Joel Brobecker, le Sun 23 Nov 2014 11:44:52 +0400, a écrit :
> > -      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
> > +      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));
> 
> Suggest using "sizeof (struct procinfo)", which I think is better
> than dereferencing a NULL pointer. This is based on guessing that
> type procinfo_t is a pointer to struct procinfo, as suggested by
> the code in inf_validate_procinfo.

Not, that is not the same: struct procinfo has an open array at its end
(threadinfos[0]), and thus the actually allocated size is variable.

Samuel


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

* Re: [PATCH,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-23  9:13   ` Samuel Thibault
@ 2014-11-23  9:56     ` Joel Brobecker
  2014-11-23 15:21       ` Samuel Thibault
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2014-11-23  9:56 UTC (permalink / raw)
  To: bug-hurd, thomas, gdb-patches

> > > -      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
> > > +      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len * sizeof (*(procinfo_t) 0));
> > 
> > Suggest using "sizeof (struct procinfo)", which I think is better
> > than dereferencing a NULL pointer. This is based on guessing that
> > type procinfo_t is a pointer to struct procinfo, as suggested by
> > the code in inf_validate_procinfo.
> 
> Not, that is not the same: struct procinfo has an open array at its end
> (threadinfos[0]), and thus the actually allocated size is variable.

OK. I don't know the code well enough to make any better suggestion.
The above does look unusual to me, but if it works and seems to be
the only correct way, let's go with that.

Should I push your patch?

-- 
Joel


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

* Re: [PATCHv2,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-23  7:44 ` Joel Brobecker
  2014-11-23  9:13   ` Samuel Thibault
@ 2014-11-23 15:19   ` Samuel Thibault
  2014-11-24  9:28     ` Joel Brobecker
  1 sibling, 1 reply; 7+ messages in thread
From: Samuel Thibault @ 2014-11-23 15:19 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: bug-hurd, thomas, gdb-patches

2014-10-02  Samuel Thibault  <samuel.thibault@ens-lyon.org>

	* gdb/gnu-nat.c (inf_validate_procinfo): Multiply the number of
	elements pi_len by the size of the elements before calling
	vm_deallocate.
	(inf_validate_task_sc): Likewise, and properly deallocate the
	noise array.

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index d17a750..6dbf31d 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -804,7 +804,8 @@ inf_validate_procinfo (struct inf *inf)
       inf->nomsg = !!(pi->state & PI_NOMSG);
       if (inf->nomsg)
 	inf->traced = !!(pi->state & PI_TRACED);
-      vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+      vm_deallocate (mach_task_self (), (vm_address_t) pi,
+		     pi_len * sizeof (*(procinfo_t) 0));
       if (noise_len > 0)
 	vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
     }
@@ -844,9 +845,10 @@ inf_validate_task_sc (struct inf *inf)
 
   suspend_count = pi->taskinfo.suspend_count;
 
-  vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+  vm_deallocate (mach_task_self (), (vm_address_t) pi,
+		 pi_len * sizeof (*(procinfo_t) 0));
   if (noise_len > 0)
-    vm_deallocate (mach_task_self (), (vm_address_t) pi, pi_len);
+    vm_deallocate (mach_task_self (), (vm_address_t) noise, noise_len);
 
   if (inf->task->cur_sc < suspend_count)
     {


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

* Re: [PATCH,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-23  9:56     ` Joel Brobecker
@ 2014-11-23 15:21       ` Samuel Thibault
  0 siblings, 0 replies; 7+ messages in thread
From: Samuel Thibault @ 2014-11-23 15:21 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: bug-hurd, thomas, gdb-patches

Joel Brobecker, le Sun 23 Nov 2014 13:56:29 +0400, a écrit :
> The above does look unusual to me, but if it works and seems to be
> the only correct way, let's go with that.

It is a system interface actually, so we don't really have the choice :)

Samuel


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

* Re: [PATCHv2,Hurd] Fix deallocation after proc_getprocinfo call
  2014-11-23 15:19   ` [PATCHv2,Hurd] " Samuel Thibault
@ 2014-11-24  9:28     ` Joel Brobecker
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Brobecker @ 2014-11-24  9:28 UTC (permalink / raw)
  To: bug-hurd, thomas, gdb-patches

> 2014-10-02  Samuel Thibault  <samuel.thibault@ens-lyon.org>
> 
> 	* gdb/gnu-nat.c (inf_validate_procinfo): Multiply the number of
> 	elements pi_len by the size of the elements before calling
> 	vm_deallocate.
> 	(inf_validate_task_sc): Likewise, and properly deallocate the
> 	noise array.

Thank you, Samuel. The patch has now been pushed.

-- 
Joel


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

end of thread, other threads:[~2014-11-24  9:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-02 15:26 [PATCH,Hurd] Fix deallocation after proc_getprocinfo call Samuel Thibault
2014-11-23  7:44 ` Joel Brobecker
2014-11-23  9:13   ` Samuel Thibault
2014-11-23  9:56     ` Joel Brobecker
2014-11-23 15:21       ` Samuel Thibault
2014-11-23 15:19   ` [PATCHv2,Hurd] " Samuel Thibault
2014-11-24  9:28     ` Joel Brobecker

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