From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id F401E384B808 for ; Mon, 1 Mar 2021 12:44:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F401E384B808 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 20C4CAC24; Mon, 1 Mar 2021 12:44:32 +0000 (UTC) Date: Mon, 1 Mar 2021 13:44:30 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [PATCH] Fix assert after goto failure Message-ID: <20210301124429.GA14163@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Mar 2021 12:44:34 -0000 Hi, Consider the following code in function dwz: ... else if (write_aranges (dso)) { cleanup (); failure: ret = 1; } ... char *p1 = realpath (file, NULL); char *p2 = realpath (multifile, NULL); ... if (p1 == NULL || p2 == NULL) { ... error (0, 0, "Could not compute relative multifile " "pathname from %s to %s", file, multifile); goto failure; ... I've managed to triggered this error in the following way. First we do this setup: ... $ mkdir tmpdir $ ln -s tmpdir tmpdir-slink $ cp hello 1 $ cp 1 2 ... Then we want to run dwz with a common file in tmpdir using the symlink tmpdir-slink: ... $ dwz -m ./tmpdir-slink/3 -r 1 2 ... but, stop just before calling realpath and remove the symlink to make the p2 realpath call return NULL. We can do that using gdb: ... $ gdb -batch \ -ex "b 15451" \ -ex run \ -ex "shell rm -f tmpdir-slink" \ -ex cont \ --args ./dwz -m ./tmpdir-slink/3 -r 1 2 Breakpoint 1 at 0x382d1: file dwz.c, line 15451. Breakpoint 1, dwz (file=0x7fffffffe285 "1", outfile=0x0, res=0x5555557a5260, resa=0x0, files=0x7fffffffdeb8) at dwz.c:15451 15451 if (!multifile_relative) dwz: Could not compute relative multifile pathname from 1 to ./tmpdir-slink/3 dwz: dwz.c:2170: off_htab_add_die: Assertion `*slot == NULL' failed. Program received signal SIGABRT, Aborted. 0x00007ffff75fffb7 in raise () from /lib/x86_64-linux-gnu/libc.so.6 ... but we hit an assertion. This is because cleanup is not called. Fix this by moving the failure label up one line. Any comments? Thanks, - Tom Fix assert after goto failure 2021-03-01 Tom de Vries * dwz.c (dwz): Move failure label to before cleanup. --- dwz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwz.c b/dwz.c index 8eb4f1d..d5fe7b1 100644 --- a/dwz.c +++ b/dwz.c @@ -15434,8 +15434,8 @@ dwz (const char *file, const char *outfile, struct file_result *res, } else if (write_aranges (dso)) { - cleanup (); failure: + cleanup (); ret = 1; } else