[patch] PID cmdline argument should be whole from digits

Jan Kratochvil jan.kratochvil@redhat.com
Sat Feb 13 15:20:00 GMT 2010


Hi,

# gdb ./1 1.core
Attaching to program: .../1, process 1
warning: process 1 is a cloned process
Cannot access memory at address 0x3d001006

that is scary because on a test box I ran as root.  Normally it just prints
(and loads it as a core file then):

Attaching to program: .../1, process 1
ptrace: Operation not permitted.


No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu.

strspn is already freely in use by libiberty/cplus-dem.c.

I will check it in as [obv] in several days if there are no objections.


Thanks,
Jan


2010-02-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* main.c (captured_main) <pid_or_core_arg>: Check the whole
	PID_OR_CORE_ARG consists of digit characters.

--- a/gdb/main.c
+++ b/gdb/main.c
@@ -827,10 +827,11 @@ Can't attach to process and specify a core file at the same time."));
   else if (pid_or_core_arg)
     {
       /* The user specified 'gdb program pid' or gdb program core'.
-	 If pid_or_core_arg's first character is a digit, try attach
-	 first and then corefile.  Otherwise try just corefile.  */
+	 If pid_or_core_arg's is a number, try attach first and then corefile.
+	 Otherwise try just corefile.  */
 
-      if (isdigit (pid_or_core_arg[0]))
+      if (pid_or_core_arg[0] != 0
+	  && strspn (pid_or_core_arg, "0123456789") == strlen (pid_or_core_arg))
 	{
 	  if (catch_command_errors (attach_command, pid_or_core_arg,
 				    !batch, RETURN_MASK_ALL) == 0)



More information about the Gdb-patches mailing list