From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11902 invoked by alias); 26 Nov 2012 16:12:35 -0000 Received: (qmail 11886 invoked by uid 22791); 26 Nov 2012 16:12:32 -0000 X-SWARE-Spam-Status: No, hits=-7.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS 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; Mon, 26 Nov 2012 16:12:23 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAQGCFVs032627 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Nov 2012 11:12:16 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qAQFj6IX032351; Mon, 26 Nov 2012 10:45:07 -0500 Message-ID: <50B38E82.1020102@redhat.com> Date: Mon, 26 Nov 2012 16:12:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Pierre Muller CC: gdb-patches@sourceware.org, rustyBSD@gmx.fr Subject: Re: [PATCH] Fix readlink calls in GDB References: <20121126142036.10142.97678.stgit@brno.lan> <004401cdcbe4$524136c0$f6c3a440$@muller@ics-cnrs.unistra.fr> <50B38790.5090206@redhat.com> <005301cdcbeb$1b177e50$51467af0$@muller@ics-cnrs.unistra.fr> In-Reply-To: <005301cdcbeb$1b177e50$51467af0$@muller@ics-cnrs.unistra.fr> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: 2012-11/txt/msg00661.txt.bz2 On 11/26/2012 03:31 PM, Pierre Muller wrote: > I don't see any code setting the terminal char to '\0' > in fbsd_pid_to_exec_file (fbsd-nat.c:40 rev 1.29) char * fbsd_pid_to_exec_file (int pid) { size_t len = MAXPATHLEN; char *buf = xcalloc (len, sizeof (char)); ^^^^^^^ char *path; xcalloc memsets the memory to zero before returning. See man calloc. > nor in linux_child_pid_to_exec_file (linux-nat.c:4311 rev 1.261) static char * linux_child_pid_to_exec_file (int pid) { char *name1, *name2; name1 = xmalloc (MAXPATHLEN); name2 = xmalloc (MAXPATHLEN); make_cleanup (xfree, name1); make_cleanup (xfree, name2); memset (name2, 0, MAXPATHLEN); ^^^^^^ That memset clear the whole buffer, thus the buffer ends up always nul-terminated. > nor in nbsd_pid_to_exec_file (nbsd-nat.c:30 rev 1.10)... That likewise uses xcalloc. -- Pedro Alves