From patchwork Fri Apr 11 14:28:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Nikulichev X-Patchwork-Id: 506 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 659A2360060 for ; Fri, 11 Apr 2014 07:29:09 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id 1172F6295E020; Fri, 11 Apr 2014 07:29:03 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id B49786295E035 for ; Fri, 11 Apr 2014 07:29:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:date:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=pRr tAITOOZEdpWPIJhYbBfOSeqltr902sPlFyArX4yvbuRas3/BIeAGw53/PI/iUpQn 5VItUW5CY7v1F0alTZoGACiLWPUXpXcjTN2jn0wekZCeGsSMvWBWm93fvftRrCFQ LHIpcblw6fj6ZLzLd6+Ymyb0x5R4bQusFjB8jKkM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:date:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=NuSqWoO6a fh03iMtAk8foSv545E=; b=hvmJv1ZnSnvrvI9uh/1KS+JFu36cS59QjyfAHVXQZ UogAdgWX3LW7PVkWRfh5aRuC8U+0tsoBIABEXPuYHH8E+GGCSf0tNtoBs7O8fsGO VNHabETHE9qnTewfROiK5lD5xb3QnQt7GC53bWO8eFMSqGqZrafeDK9c76izjkfr 70= Received: (qmail 21271 invoked by alias); 11 Apr 2014 14:29:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 21261 invoked by uid 89); 11 Apr 2014 14:29:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 X-HELO: mx.tbricks.com Received: from mx.tbricks.com (HELO mx.tbricks.com) (212.247.19.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Apr 2014 14:28:57 +0000 Received: from [10.200.144.43] (HELO mx2.tbricks.com) by mx.tbricks.com (CommuniGate Pro SMTP 5.2.20) with ESMTP id 7003582; Fri, 11 Apr 2014 16:28:55 +0200 Received: from [10.200.144.218] (account nvs@tbricks.com) by mx2.tbricks.com (CommuniGate Pro WEBUSER 5.2.20) with HTTP id 7508893; Fri, 11 Apr 2014 18:28:55 +0400 From: "Vladimir Nikulichev" Subject: [PATCH] Disable check for NUL bytes in /proc/pid/cmdline To: gdb-patches@sourceware.org Date: Fri, 11 Apr 2014 18:28:55 +0400 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in When I execute gcore on a process, it prints warning that /proc/pid/cmdline contains null characters: $ gcore 18706 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". 0x00007fa23be3c5c3 in __select_nocancel () from /lib64/libc.so.6 warning: target file /proc/18706/cmdline contained unexpected null characters Saved corefile core.18706 There's nothing wrong, null characters separate command line arguments from each other. This fix disables the check when reading cmdline. gdb: 2014-04-10 Vladimir Nikulichev * target.h (target_fileio_read_stralloc): Add 'check_null' argument. * target.c (target_fileio_read_stralloc): Make check for NULs optional. * linux-tdep.c (linux_info_proc, linux_fill_prpsinfo): Disable check for NULs in /proc/pid/cmdline. --- /* Tracepoint-related operations. */ diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 45a94a8..8da7244 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2014-04-10 Vladimir Nikulichev + + * target.h (target_fileio_read_stralloc): Add + 'check_null' argument. + * target.c (target_fileio_read_stralloc): Make + check for NULs optional. + * linux-tdep.c (linux_info_proc, linux_fill_prpsinfo): + Disable check for NULs in /proc/pid/cmdline. + 2014-04-10 Pedro Alves * breakpoint.c (single_step_breakpoints) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index c10b8ee..4391e1a 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -351,7 +351,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args, if (cmdline_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid); - data = target_fileio_read_stralloc (filename); + data = target_fileio_read_stralloc (filename, 0); if (data) { struct cleanup *cleanup = make_cleanup (xfree, data); @@ -390,7 +390,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args, if (mappings_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/maps", pid); - data = target_fileio_read_stralloc (filename); + data = target_fileio_read_stralloc (filename, 1); if (data) { struct cleanup *cleanup = make_cleanup (xfree, data); @@ -451,7 +451,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args, if (status_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/status", pid); - data = target_fileio_read_stralloc (filename); + data = target_fileio_read_stralloc (filename, 1); if (data) { struct cleanup *cleanup = make_cleanup (xfree, data); @@ -464,7 +464,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args, if (stat_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/stat", pid); - data = target_fileio_read_stralloc (filename); + data = target_fileio_read_stralloc (filename, 1); if (data) { struct cleanup *cleanup = make_cleanup (xfree, data); @@ -753,13 +753,13 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", current_inferior ()->pid); - data = target_fileio_read_stralloc (mapsfilename); + data = target_fileio_read_stralloc (mapsfilename, 1); if (data == NULL) { /* Older Linux kernels did not support /proc/PID/smaps. */ xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", current_inferior ()->pid); - data = target_fileio_read_stralloc (mapsfilename); + data = target_fileio_read_stralloc (mapsfilename, 1); } if (data) { @@ -1273,7 +1273,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) /* Obtaining PID and filename. */ pid = ptid_get_pid (inferior_ptid); xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid); - fname = target_fileio_read_stralloc (filename); + fname = target_fileio_read_stralloc (filename, 0); if (fname == NULL || *fname == '\0') { @@ -1306,7 +1306,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) p->pr_psargs[sizeof (p->pr_psargs) - 1] = '\0'; xsnprintf (filename, sizeof (filename), "/proc/%d/stat", (int) pid); - proc_stat = target_fileio_read_stralloc (filename); + proc_stat = target_fileio_read_stralloc (filename, 1); make_cleanup (xfree, proc_stat); if (proc_stat == NULL || *proc_stat == '\0') @@ -1387,7 +1387,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) /* Finally, obtaining the UID and GID. For that, we read and parse the contents of the `/proc/PID/status' file. */ xsnprintf (filename, sizeof (filename), "/proc/%d/status", (int) pid); - proc_status = target_fileio_read_stralloc (filename); + proc_status = target_fileio_read_stralloc (filename, 1); make_cleanup (xfree, proc_status); if (proc_status == NULL || *proc_status == '\0') diff --git a/gdb/target.c b/gdb/target.c index 1b48f79..e6f9c3c 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2895,7 +2895,7 @@ target_fileio_read_alloc (const char *filename, gdb_byte **buf_p) if the result contains any embedded NUL bytes. */ char * -target_fileio_read_stralloc (const char *filename) +target_fileio_read_stralloc (const char *filename, int check_null) { gdb_byte *buffer; char *bufstr; @@ -2912,6 +2912,9 @@ target_fileio_read_stralloc (const char *filename) bufstr[transferred] = 0; + if (!check_null) + return bufstr; + /* Check for embedded NUL bytes; but allow trailing NULs. */ for (i = strlen (bufstr); i < transferred; i++) if (bufstr[i] != 0) diff --git a/gdb/target.h b/gdb/target.h index d7c6c3d..2d11a99 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1890,7 +1890,8 @@ extern LONGEST target_fileio_read_alloc (const char *filename, or the transfer is unsupported, NULL is returned. Empty objects are returned as allocated but empty strings. A warning is issued if the result contains any embedded NUL bytes. */ -extern char *target_fileio_read_stralloc (const char *filename); +extern char *target_fileio_read_stralloc (const char *filename, + int check_null);