From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19438 invoked by alias); 28 May 2010 18:25:05 -0000 Received: (qmail 19419 invoked by uid 22791); 28 May 2010 18:25:04 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 May 2010 18:24:59 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4SIOoqQ012743 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 May 2010 14:24:50 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4SIOloY010713 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 May 2010 14:24:49 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o4SIOlYl029856; Fri, 28 May 2010 20:24:47 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o4SIOkYL029855; Fri, 28 May 2010 20:24:46 +0200 Date: Fri, 28 May 2010 18:28:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [patch] Fix crash on /proc/PID/stat race Message-ID: <20100528182446.GA22376@host0.dyn.jankratochvil.net> References: <20100527175404.GA16087@host0.dyn.jankratochvil.net> <201005272000.26518.pedro@codesourcery.com> <20100527212037.GA24735@host0.dyn.jankratochvil.net> <201005272325.40987.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201005272325.40987.pedro@codesourcery.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-05/txt/msg00686.txt.bz2 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 + * linux-nat.c (linux_nat_core_of_thread_1): Fix crash on invalid + CONTENT. + +2010-05-28 Jan Kratochvil + * 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 + + * linux-low.c (linux_core_of_thread): Fix crash on invalid CONTENT. + New comment. + 2010-05-26 Ozkan Sezer * 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);