Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Fix crash on /proc/PID/stat race
@ 2010-05-27 18:00 Jan Kratochvil
  2010-05-27 19:06 ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2010-05-27 18:00 UTC (permalink / raw)
  To: gdb-patches

Hi,

got a reported a core file that gdb crashes in linux_nat_core_of_thread_1
called from linux_nat_wait_1 on TARGET_WAITKIND_EXITED.  It crashes because
CONTENT is empty there.

While it is understanable /proc/PID/stat is not available after
TARGET_WAITKIND_EXITED I failed to artificially reproduce it by
	sleep 1&p=$!;(sleep 2;cat) </proc/$p/stat
as it prints
	cat: -: No such process
due to
	read(0, 0x65d000, 32768) = -1 ESRCH (No such process)

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

Checked the gdb.mi/*.exp gdb.log still contains some "core" values.


Thanks,
Jan


2010-05-27  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-nat.c (linux_nat_core_of_thread_1): Fix crash on invalid
	CONTENT.

--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -5502,16 +5502,23 @@ linux_nat_core_of_thread_1 (ptid_t ptid)
 
   make_cleanup (xfree, content);
 
+  /* Do not assume anything about CONTENT.  In some race fopen can be still
+     successful but CONTENT_READ can be 0 for an exited process.  */
+
   p = strchr (content, '(');
-  p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */
+  if (p != NULL)
+    p = strchr (p, ')');
+  if (p != NULL)
+    p++;
 
   /* If the first field after program name has index 0, then core number is
      the field with index 36.  There's no constant for that anywhere.  */
-  p = strtok_r (p, " ", &ts);
-  for (i = 0; i != 36; ++i)
+  if (p != NULL)
+    p = strtok_r (p, " ", &ts);
+  for (i = 0; p != NULL && i != 36; ++i)
     p = strtok_r (NULL, " ", &ts);
 
-  if (sscanf (p, "%d", &core) == 0)
+  if (p == NULL || sscanf (p, "%d", &core) == 0)
     core = -1;
 
   do_cleanups (back_to);


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

end of thread, other threads:[~2010-05-28 18:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-27 18:00 [patch] Fix crash on /proc/PID/stat race Jan Kratochvil
2010-05-27 19:06 ` Pedro Alves
2010-05-27 21:24   ` Jan Kratochvil
2010-05-27 22:50     ` Pedro Alves
2010-05-28 18:28       ` Jan Kratochvil

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