From patchwork Wed Jul 19 11:27:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 72931 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AC193858002 for ; Wed, 19 Jul 2023 11:29:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AC193858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689766182; bh=HrIAeclE/9mg9lm/6HfUHbQfj6AX5wWEtyPY59A2QBs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Kn/Y4vY3H7I4Y4VxFE2MSsPuJHkSZzF4mPOMhlCqUEGvIVjgPDDSV2NZ/uem9bdaa GBkaLN16qwrmruu+sh067UvjoZFkfX/a++ARzeo+v03dDiQvPcETzITpJKG6Mq6zih 4j5fFzZzg8BrjmVD8ZHwkXBqbiU6OTiK/wrOBD+Y= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id BA4773858C66 for ; Wed, 19 Jul 2023 11:29:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA4773858C66 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36JAjaat002502; Wed, 19 Jul 2023 11:29:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rxebxrxfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jul 2023 11:29:15 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36JBTFds021288; Wed, 19 Jul 2023 11:29:15 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rxebxrxfb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jul 2023 11:29:15 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 36J8V2cs029625; Wed, 19 Jul 2023 11:29:13 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv6smhc6h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jul 2023 11:29:13 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36JBTBkk57344392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jul 2023 11:29:11 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB58F2004B; Wed, 19 Jul 2023 11:29:11 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF6A420043; Wed, 19 Jul 2023 11:29:11 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Jul 2023 11:29:11 +0000 (GMT) To: Tom Tromey , Bruno Larsen Cc: gdb-patches@sourceware.org, Ilya Leoshkevich Subject: [PATCH v2] gdb: Fix "target file /proc/.../cmdline contained unexpected null characters" Date: Wed, 19 Jul 2023 13:27:45 +0200 Message-ID: <20230719112909.1843509-1-iii@linux.ibm.com> X-Mailer: git-send-email 2.41.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: zUBAhpmSB8vTaeYtBTFnbqZrI_3VYqiB X-Proofpoint-ORIG-GUID: 0IMI2l4ZTPxef_XHsUNmF6ejvPwMqHcO X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-19_06,2023-07-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307190100 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ilya Leoshkevich via Gdb-patches From: Ilya Leoshkevich Reply-To: Ilya Leoshkevich Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When using the gcore command, GDB prints the following warning: (gdb) gcore warning: target file /proc/.../cmdline contained unexpected null characters The reason is that cmdline is read with target_fileio_read_stralloc(), which warns on seeing null characters. However, it's perfectly valid for cmdline to contain \0s, so switch to target_fileio_read_alloc(). Reviewed-By: Bruno Larsen --- v1: https://sourceware.org/pipermail/gdb-patches/2023-June/200436.html https://sourceware.org/pipermail/gdb-patches/2023-July/200993.html v1 -> v2: Improve the commit message (Bruno). Handle the missing trailing '\0' (Bruno). gdb/linux-tdep.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index b5eee5e108c..90ad02310b3 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1902,15 +1902,23 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) pid = inferior_ptid.pid (); xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid); /* The full name of the program which generated the corefile. */ - gdb::unique_xmalloc_ptr fname - = target_fileio_read_stralloc (NULL, filename); + gdb_byte *buf = NULL; + size_t buf_len = target_fileio_read_alloc (NULL, filename, &buf); + gdb::unique_xmalloc_ptr fname ((char *)buf); - if (fname == NULL || fname.get ()[0] == '\0') + if (buf_len < 1 || fname.get ()[0] == '\0') { /* No program name was read, so we won't be able to retrieve more information about the process. */ return 0; } + if (fname.get ()[buf_len - 1] != '\0') + { + warning (_("target file %s " + "does not contain a trailing null character"), + filename); + return 0; + } memset (p, 0, sizeof (*p));