Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Fix crash on /proc/PID/stat race
Date: Fri, 28 May 2010 18:28:00 -0000	[thread overview]
Message-ID: <20100528182446.GA22376@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <201005272325.40987.pedro@codesourcery.com>

On Fri, 28 May 2010 00:25:40 +0200, Pedro Alves wrote:
> Yes, exactly.  Thanks.

Checked-in:
	http://sourceware.org/ml/gdb-cvs/2010-05/msg00243.html


> As long as a process hasn't been waited for, the /stat entry should exist,
> even if the process is zombie.

I agree but still finding such external dependency needlessly fragile.


> Anyway, if you want to put that one in, it's okay, but please don't
> lose the comment below:
> 
> > -  p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */
> > +  if (p != NULL)
> > +    p = strchr (p, ')');

The part "and a whitespace." was removed as redundant (due to the following
strtok_r) while getting more complicated making it safe.  In the spirit of GNU
Coding Style
	"It is not necessary to duplicate in words the meaning of the
	C argument declarations"
(while used in a different meaning at that point) I removed the remainder of
the comment
	/* skip ")" */
for the block
	  if (p != NULL)
	    p = strchr (p, ')');
	  if (p != NULL)
	    p++;
as obvious; but I put it back now on your request.


> and I don't think the fopen race comment makes sense > as is anymore.

OK, removed that comment.


> Also, IWBN if gdbserver was fixed similarly, but I won't ask
> you to do that.  :-)

Forgot/unaware, fixed the same way.

Checked-in.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-05/msg00244.html

--- src/gdb/ChangeLog	2010/05/28 18:00:41	1.11855
+++ src/gdb/ChangeLog	2010/05/28 18:23:13	1.11856
@@ -1,5 +1,10 @@
 2010-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* linux-nat.c (linux_nat_core_of_thread_1): Fix crash on invalid
+	CONTENT.
+
+2010-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* linux-nat.c (linux_nat_wait_1): Do not call
 	linux_nat_core_of_thread_1 on TARGET_WAITKIND_EXITED or
 	TARGET_WAITKIND_SIGNALLED.
--- src/gdb/gdbserver/ChangeLog	2010/05/26 22:40:22	1.386
+++ src/gdb/gdbserver/ChangeLog	2010/05/28 18:23:15	1.387
@@ -1,3 +1,8 @@
+2010-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* linux-low.c (linux_core_of_thread): Fix crash on invalid CONTENT.
+	New comment.
+
 2010-05-26  Ozkan Sezer  <sezeroz@gmail.com>
 
 	* gdbreplay.c (remote_open): Check error return from socket() call by
--- src/gdb/linux-nat.c	2010/05/28 18:00:46	1.169
+++ src/gdb/linux-nat.c	2010/05/28 18:23:15	1.170
@@ -5509,15 +5509,21 @@
   make_cleanup (xfree, content);
 
   p = strchr (content, '(');
-  p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */
+
+  /* Skip ")".  */
+  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);
--- src/gdb/gdbserver/linux-low.c	2010/05/03 04:02:20	1.148
+++ src/gdb/gdbserver/linux-low.c	2010/05/28 18:23:15	1.149
@@ -4346,13 +4346,21 @@
     }
 
   p = strchr (content, '(');
-  p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */
 
-  p = strtok_r (p, " ", &ts);
-  for (i = 0; i != 36; ++i)
+  /* Skip ")".  */
+  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.  */
+  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;
 
   free (content);


      reply	other threads:[~2010-05-28 18:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-27 18:00 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100528182446.GA22376@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox