From patchwork Wed Dec 7 14:11:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 30875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp208389wrr; Wed, 7 Dec 2022 06:15:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KKz3cUotpR/Jai+q/ppMCNnmnSr4zO2VY9b5+XaDxm8SBE+UOMbU0TmhlEUcE7MW+d3oW X-Received: by 2002:aa7:d0d4:0:b0:46b:fa4:a827 with SMTP id u20-20020aa7d0d4000000b0046b0fa4a827mr41463528edo.30.1670422508706; Wed, 07 Dec 2022 06:15:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670422508; cv=none; d=google.com; s=arc-20160816; b=lJaNG7cSxGCnsr4I1I9Y4y3enM4JbTKjvcitxKh94JPMG9Youf0UA3mtakHZ/EZX/6 WTlPGoHE0Rv5h122j8mu3o+xnjgj/KYXcBwz22tP17qTOiDs/2ilqEeO/qgUvw1mUKh8 z54w30nsDaxRlB/5BU3KxtzWRcrA4qyn28ZIfqkcMy9FgWgWTq2rqwVYhcep3e2Cyud6 2xos8uwGJbsKd+azKyvxsCGoPgFXAPk0LrV8errm1s/yGZmNjD+txGVmLEyKrUINHEY0 IYtutOPlNOrH5+8J/CGl9+5UNVX2eOWcgJjiypAWibNTMBpdJeAsalgUzqqv4PtnHLRe IcFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=M6z3BAaUfXC5jz7YsVgCRijkIicfznr/Ei8/Ek9o3QU=; b=Mdk3xw6MQYDyDVCA0Mq7GNO6XYBnj5xuZx8IUVJKwGB3pP3luMgCGQhxbc9UWI8u9J ukmOOQSHJ+z4rLhaFdNVKfl/JPt0dKfoARWiRmjHXX5zKvWpcMFqHJaXYB8veEK2IVLp obFJW2Tq9D4SumBh7EBXPh8wokIyTZxhph6HgfWaXRQkmQWJSavfflb0BJ7YtuIPfk30 6Bmz980Q1fBDcKzVfgVswWKhMZT4op5YhIQzXkx5z+aMuh2TakWL1Yg2Vc4vVtQbeNEX Z0pJ234bFf/pjZNG16Vd4Z5s57AjO6Z5xo+sbdf8WzUMhqwNR3I4b4fIyhMq721EbEZc Qmnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=PSurGv3Z; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a13-20020a170906684d00b007bf848e0a05si12826054ejs.912.2022.12.07.06.15.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 06:15:08 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=PSurGv3Z; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 356E5381ECAF for ; Wed, 7 Dec 2022 14:15:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 356E5381ECAF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670422507; bh=M6z3BAaUfXC5jz7YsVgCRijkIicfznr/Ei8/Ek9o3QU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PSurGv3ZTZypvL5Hl+fWNwlPl7PueXTMskJyz8lXtIHunqPaxhs1fN9bMCj7tqcgj Yu+hqibLylpa4k/CSucJLO3/SIU74MU1BrSAka2xBLOwZdGnNTI1RTilakw+Qh/a/U nEt049rLxx0yuH35RkfpzBn5e4zuTFXWKXloEao8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id C26D7382B3C0 for ; Wed, 7 Dec 2022 14:14:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C26D7382B3C0 X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="403169044" X-IronPort-AV: E=Sophos;i="5.96,225,1665471600"; d="scan'208";a="403169044" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2022 06:14:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="646617921" X-IronPort-AV: E=Sophos;i="5.96,225,1665471600"; d="scan'208";a="646617921" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2022 06:14:54 -0800 To: binutils@sourceware.org Cc: Felix Willgerodt Subject: [PATCH 1/1] libctf: Fix double free in ctf_link_add_cu_mapping. Date: Wed, 7 Dec 2022 15:11:37 +0100 Message-Id: <20221207141137.1527113-1-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Felix Willgerodt via Binutils From: Felix Willgerodt Reply-To: Felix Willgerodt Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751564952671551742?= X-GMAIL-MSGID: =?utf-8?q?1751564952671551742?= This fixes a potential double free which can occur if we jump to oom_noerrno after the first free. I am not very familiar with libctf, so any comments are welcome. I am wondering if the right solution wouldn't be to free both t and f before the "return 0". But I didn't fully understand the code and saw that other users of ctf_dynhash_insert() also don't free the key manually. libctf/ChangeLog: * ctf-link.c (ctf_link_add_cu_mapping): Adjust freeing logic. --- libctf/ctf-link.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c index 702f2b4d5fe..e59e415eb41 100644 --- a/libctf/ctf-link.c +++ b/libctf/ctf-link.c @@ -430,8 +430,6 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to) goto oom_noerrno; } } - else - free (t); if (ctf_dynhash_insert (one_out, f, NULL) < 0) {