From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@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 14:29:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8;format="flowed" Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2014-04/txt/msg00204.txt.bz2 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. --- 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); /* Tracepoint-related operations. */