From patchwork Tue Aug 6 09:00:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754580 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D01A91BE23B for ; Tue, 6 Aug 2024 09:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934821; cv=none; b=cdoPFsQSV7HPA5okaop9m1kTGQ6vD86gf0brX8V0kTpnEpadECuSFWoRd/3TVtaolJU7Bq02iQGDntl4m+DgCXP1jvPY0J3I6LgkdauLoT6Da9Aud8NrJnlxEx91HbWjGH4jb3DLRDWdTem00MtTk0qrDbQ8FCVeLLqtDHAx/LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722934821; c=relaxed/simple; bh=RQRXrqpERnAif0kCcipd8LxXZj1eE1n1uzNB7UK5Eq8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E4pQFhYyUvSRh5Uro9E96Tsw0U/puwjOmPUp7IwbtNaBkJ7rCAlSq+QZQ1z5ehW/kIzbVxQq9NxmDMUUqyKstToGTvtlPX+Xy86yNodx2QU06GTOLj3afC+x7wzikwuB3P1iRKbw7NM9qq1fKVeJsQUc4+jHUQ7RObOmosBRpD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Ae0t0ZIo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ml466H41; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Ae0t0ZIo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ml466H41" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E71141151B2B for ; Tue, 6 Aug 2024 05:00:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 06 Aug 2024 05:00:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722934818; x=1723021218; bh=/PJWPFn/g6 nEx0KDyCPtpwNhTmFlt4rK976wqaN6fd4=; b=Ae0t0ZIo4UKcye2mWsJYDY2SwU sZgANoZ98+AoOo5QTQ1+Vg9sS2J7n3KmyyKxKJwlezVQsTAU3xJdQ+SHYeOjTYzq E1QsnYeVpuhS+HlZEDjadUSzwkK0rpwzM9tm9ImIPXKgGDfSjhWTpqEhwXrkH2GA wAOY37OvK444brBjeaND0vX+NvpU3qwsvjb5AxDJeYCHI4j8Oq6qsyoFMSUZPfUu VRI0j3Bj1NMTT/7Ld+CbEK/M9hrS/ddZzkSgPqBB7Ar1ibAAVOTV5kvrB7By/cnr DoKZ3URxECOjCUFCPM6SQf47jNrx1JhzZlTWMv3Lg0b6KRbgCVCg8ewEeWIg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722934818; x=1723021218; bh=/PJWPFn/g6nEx0KDyCPtpwNhTmFl t4rK976wqaN6fd4=; b=ml466H41Iiye1w6dZwnHQC+3Vcky0xXeOsE5wd/vP+tO T8pu9To8kONrEWvATKIQDtp7cP5r8bY8ehNqXiMKsfjQugxREvLlmqC8n32ddM5O Bs/8dfW5qE//tl45qM6TLuXgxOS5yRuUoIwCgFi6YxMN73+JetImfOecL5Tgu+fy 9fxZ7QaY8Yzh/vcTxynt5c3IjCXzZszOQaQokc21GQuLVJn51ChbhZbMAqhjjpdo DNMhhLaaJ9xoHA/h81fy633JMOrJj2bYbWfRmNJiH3tIu3CTw2RpeHW7OoCETThM 0Kj9BoOwsNF2Bk4QC5b6kmyW8/VXyGBjWouGsSTyAg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 6 Aug 2024 05:00:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f7cb2d13 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 6 Aug 2024 09:00:16 +0000 (UTC) Date: Tue, 6 Aug 2024 11:00:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/22] builtin/rebase: fix leaking `commit.gpgsign` value Message-ID: <05290fc1f14cae8229c42f2d0aafe6619c069e3a.1722933642.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `get_replay_opts()`, we unconditionally override the `gpg_sign` field that already got populated by `sequencer_init_config()` in case the user has "commit.gpgsign" set in their config. It is kind of dubious whether this is the correct thing to do or a bug. What is clear though is that this creates a memory leak. Let's mark this assignment with a TODO comment to figure out whether this needs to be fixed or not. Meanwhile though, let's plug the memory leak. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 8 ++++++++ sequencer.c | 1 + t/t3404-rebase-interactive.sh | 1 + t/t3435-rebase-gpg-sign.sh | 1 + t/t7030-verify-tag.sh | 1 + 5 files changed, 12 insertions(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index e3a8e74cfc..f65316a023 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -186,7 +186,15 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.committer_date_is_author_date = opts->committer_date_is_author_date; replay.ignore_date = opts->ignore_date; + + /* + * TODO: Is it really intentional that we unconditionally override + * `replay.gpg_sign` even if it has already been initialized via the + * configuration? + */ + free(replay.gpg_sign); replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); + replay.reflog_action = xstrdup(opts->reflog_action); if (opts->strategy) replay.strategy = xstrdup_or_null(opts->strategy); diff --git a/sequencer.c b/sequencer.c index 0291920f0b..cade9b0ca8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v, } if (!strcmp(k, "commit.gpgsign")) { + free(opts->gpg_sign); opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL; return 0; } diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index f92baad138..f171af3061 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -26,6 +26,7 @@ Initial setup: touch file "conflict". ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3435-rebase-gpg-sign.sh b/t/t3435-rebase-gpg-sign.sh index 6aa2aeb628..6e329fea7c 100755 --- a/t/t3435-rebase-gpg-sign.sh +++ b/t/t3435-rebase-gpg-sign.sh @@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-rebase.sh" . "$TEST_DIRECTORY/lib-gpg.sh" diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh index 6f526c37c2..effa826744 100755 --- a/t/t7030-verify-tag.sh +++ b/t/t7030-verify-tag.sh @@ -4,6 +4,7 @@ test_description='signed tag tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh"