From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101148 invoked by alias); 20 Jan 2016 15:54:17 -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 101138 invoked by uid 89); 20 Jan 2016 15:54:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL,BAYES_40,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=Jon, HX-CTCH-RefID:0.000,recu, Hx-languages-length:1754, H*F:D*org.uk X-HELO: rgout0205.bt.lon5.cpcloud.co.uk Received: from rgout0205.bt.lon5.cpcloud.co.uk (HELO rgout0205.bt.lon5.cpcloud.co.uk) (65.20.0.204) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Jan 2016 15:54:15 +0000 X-OWM-Source-IP: 86.141.131.231 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-CTCH-RefID: str=0001.0A090202.569FADA5.007B,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-Junkmail-Premium-Raw: score=27/50,refid=2.7.2:2016.1.11.150617:17:27.888,ip=86.141.131.231,rules=__HAS_FROM, __TO_MALFORMED_2, __TO_NO_NAME, __SUBJ_ALPHA_END, __HAS_MSGID, __SANE_MSGID, __HAS_X_MAILER, __ANY_URI, __HTTPS_URI, URI_ENDS_IN_HTML, __URI_NO_WWW, __URI_NO_PATH, __URI_IN_BODY, BODYTEXTP_SIZE_3000_LESS, BODY_SIZE_1800_1899, __MIME_TEXT_ONLY, RDNS_GENERIC_POOLED, __URI_NS, SXL_IP_DYNAMIC[231.131.141.86.fur], HTML_00_01, HTML_00_10, BODY_SIZE_5000_LESS, RDNS_SUSP_GENERIC, BODY_SIZE_2000_LESS, RDNS_SUSP, BODY_SIZE_7000_LESS, __SINGLE_URI_TEXT, SINGLE_URI_IN_BODY X-CTCH-Spam: Unknown Received: from localhost.localdomain (86.141.131.231) by rgout02.bt.lon5.cpcloud.co.uk (8.6.122.06) (authenticated as jonturney@btinternet.com) id 568E3782017A95F1; Wed, 20 Jan 2016 15:54:06 +0000 From: Jon Turney To: gdb-patches@sourceware.org Cc: Jon Turney Subject: [PATCH] Better handling for realpath() failures in windows_make_so() on Cygwin Date: Wed, 20 Jan 2016 15:54:00 -0000 Message-Id: <1453305146-7364-1-git-send-email-jon.turney@dronecode.org.uk> X-SW-Source: 2016-01/txt/msg00478.txt.bz2 Fix a memory leak which would occur in the case when the result of realpath() is greater than or equal to SO_NAME_MAX_PATH_SIZE. Distinguish between realpath() failing (returning NULL), and returning a path greather than or equal to SO_NAME_MAX_PATH_SIZE. Warn rather than stopping with an error in both those cases. Original patch from Tim Chick. Memory leak fix by Corinna Vinschen. See also https://cygwin.com/ml/cygwin/2015-11/msg00353.html gdb/ChangeLog: 2016-01-20 Jon Turney * windows-nat.c (windows_make_so): Fix memory leak when realpath returns a path >= SO_NAME_MAX_PATH_SIZE. Distinguish that case from realpath failing. Warn rather than stopping with an error in both cases. --- gdb/ChangeLog | 7 +++++++ gdb/windows-nat.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 71d6670..703b407 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -642,13 +642,22 @@ windows_make_so (const char *name, LPVOID load_addr) else { char *rname = realpath (name, NULL); - if (rname && strlen (rname) < SO_NAME_MAX_PATH_SIZE) + if (rname) { - strcpy (so->so_name, rname); + if (strlen (rname) < SO_NAME_MAX_PATH_SIZE) + strcpy (so->so_name, rname); + else + { + warning (_("dll path \"%s\" too long"), rname); + strcpy (so->so_name, so->so_original_name); + } free (rname); } else - error (_("dll path too long")); + { + warning (_("dll path for \"%s\" can not be evaluated"), name); + strcpy (so->so_name, so->so_original_name); + } } /* Record cygwin1.dll .text start/end. */ p = strchr (so->so_name, '\0') - (sizeof ("/cygwin1.dll") - 1); -- 2.7.0