ASAN attach crash - 7.9 regression [Re: [PATCH 4/4] PR gdb/17471: Repeating a background command makes it foreground]

Message ID 20150803210205.GA2019@host1.jankratochvil.net
State New, archived
Headers

Commit Message

Jan Kratochvil Aug. 3, 2015, 9:02 p.m. UTC
  On Thu, 09 Oct 2014 20:00:29 +0200, Pedro Alves wrote:
> Tested on x86_64 Fedora 20, native and gdbserver.

-fsanitize=address
gdb.base/attach-pie-noexec.exp

==32586==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200004ed90 at pc 0x48ad50 bp 0x7ffceb3aef50 sp 0x7ffceb3aef20
READ of size 2 at 0x60200004ed90 thread T0
    #0 0x48ad4f in __interceptor_strlen (/home/jkratoch/redhat/gdb-test-asan/gdb/gdb+0x48ad4f)
    #1 0xeafe5c in xstrdup xstrdup.c:33
    #2 0x85e024 in attach_command /home/jkratoch/redhat/gdb-test-asan/gdb/infcmd.c:2680

regressed by:

commit 6c4486e63f7583ed85a0c72841f6ccceebbf858e
Author: Pedro Alves <palves@redhat.com>
Date:   Fri Oct 17 13:31:26 2014 +0100
    PR gdb/17471: Repeating a background command makes it foreground


OK for check-in and for 7.10?


Jan
2015-08-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/18767
	* infcmd.c (attach_command): Move ARGS_CHAIN cleanup after last ARGS
	use.
  

Comments

Pedro Alves Aug. 4, 2015, 8:35 a.m. UTC | #1
On 08/03/2015 10:02 PM, Jan Kratochvil wrote:
> On Thu, 09 Oct 2014 20:00:29 +0200, Pedro Alves wrote:
>> Tested on x86_64 Fedora 20, native and gdbserver.
> 
> -fsanitize=address
> gdb.base/attach-pie-noexec.exp
> 
> ==32586==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200004ed90 at pc 0x48ad50 bp 0x7ffceb3aef50 sp 0x7ffceb3aef20
> READ of size 2 at 0x60200004ed90 thread T0
>     #0 0x48ad4f in __interceptor_strlen (/home/jkratoch/redhat/gdb-test-asan/gdb/gdb+0x48ad4f)
>     #1 0xeafe5c in xstrdup xstrdup.c:33
>     #2 0x85e024 in attach_command /home/jkratoch/redhat/gdb-test-asan/gdb/infcmd.c:2680
> 
> regressed by:
> 
> commit 6c4486e63f7583ed85a0c72841f6ccceebbf858e
> Author: Pedro Alves <palves@redhat.com>
> Date:   Fri Oct 17 13:31:26 2014 +0100
>     PR gdb/17471: Repeating a background command makes it foreground
> 
> 
> OK for check-in and for 7.10?

OK.

Thanks,
Pedro Alves
  
Jan Kratochvil Aug. 4, 2015, 11:48 a.m. UTC | #2
On Tue, 04 Aug 2015 10:35:43 +0200, Pedro Alves wrote:
> OK.

master
	978b9495b78054b76052a09064cae8c94a58b93e
7.10
	be18bd2bb2f68cd62b94f5a176e55440c73d25b8


Jan
  
Jan Kratochvil Aug. 25, 2015, 3:47 p.m. UTC | #3
On Tue, 04 Aug 2015 13:48:26 +0200, Jan Kratochvil wrote:
> On Tue, 04 Aug 2015 10:35:43 +0200, Pedro Alves wrote:
> > OK.
> 
> master
> 	978b9495b78054b76052a09064cae8c94a58b93e
> 7.10
> 	be18bd2bb2f68cd62b94f5a176e55440c73d25b8

That 7.10 was not pushed, so it is pushed to 7.10 now as:
	fa68327bb429223d98887fa43db67fbb49629eb1


Jan
  

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 4948d27..5cd8dd7 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2617,9 +2617,6 @@  attach_command (char *args, int from_tty)
      shouldn't refer to attach_target again.  */
   attach_target = NULL;
 
-  /* Done with ARGS.  */
-  do_cleanups (args_chain);
-
   /* Set up the "saved terminal modes" of the inferior
      based on what modes we are starting it with.  */
   target_terminal_init ();
@@ -2684,12 +2681,19 @@  attach_command (char *args, int from_tty)
 	  a->async_exec = async_exec;
 	  add_inferior_continuation (attach_command_continuation, a,
 				     attach_command_continuation_free_args);
+
+	  /* Done with ARGS.  */
+	  do_cleanups (args_chain);
+
 	  return;
 	}
 
       wait_for_inferior ();
     }
 
+  /* Done with ARGS.  */
+  do_cleanups (args_chain);
+
   attach_command_post_wait (args, from_tty, async_exec);
 }