From patchwork Fri Jun 7 06:39:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13689355 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 6FB1A153BFC for ; Fri, 7 Jun 2024 06:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717742353; cv=none; b=Q2VJWjUzsUtsJ7pqIQh1NzWqyPv5P49lliEh/v/pctRt/UcJ5LVtPHj9ew9ZGbUIt7z9kqrIlLO3/1W4+oZHSSBph29dOAvzfnaB+FMHWRnoooJyGO3p+5BKnXkXIUsR6tZv0VqvN52+ppoMoxBueYti7bdkucYoXNlyupXzCaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717742353; c=relaxed/simple; bh=i67vFad5Ot5Dj8ehshhU5dTGfqtU0+gzw2E0ZAb5Rks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bsz4BcwDy/zUvP5a8OqJenVgfISpgZQynQMaMIYoLm3djpUKSaMhE1Tsyi7jTCZkgERUXm0xO7Wg4PV1CPHDOWSuFCP2KTHsJ5rQ1mPMtlmMIXxxKckG24XGfjEbAa2iUJRXcKfVeSA6IEtjRkMLk0+S1vXUkiGGmuOse4396no= 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=L0Fn4OGU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=L4S9/zYm; arc=none smtp.client-ip=103.168.172.159 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="L0Fn4OGU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="L4S9/zYm" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4EC1A11401EA; Fri, 7 Jun 2024 02:39:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 07 Jun 2024 02:39:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1717742351; x=1717828751; bh=2p27yCUu7T JgiwGnlrLZeFJDNAge3wNUQjHHxo54l54=; b=L0Fn4OGUnv45gNYovuJxb4Zvsm lZB4tDfbPEOFw0v8ftLDckFIdz596xrIzmzS/KyLHEiNQ75+WQNjAo4hphK3ggxS yH0B9DI1WlbSlyNpoa/+9IVGKe5hj7uuBs7F6yo+7COszF+sOa8DX9iCqcmdb7Gf WcsvA3+Ci76v+FH1YD2Fh5P2XlC/N8giHvj5VdqknKGpTEu5GZ/MAx/ReF+asMxL doZhn5nKQIrSO4pB6Xt//P/4lmiNPHVqQJgZ3NDm3my/Lx4wm45SVI70nyLrbNWt 5Ko4RnaOq5pEi/HhQ7mgKO1nwZPe/mNKTcOaTr5YUN0GWXG4e3F8mAeVSNww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1717742351; x=1717828751; bh=2p27yCUu7TJgiwGnlrLZeFJDNAge 3wNUQjHHxo54l54=; b=L4S9/zYm2xN98vt/CC1PWrOmfIb01bbSmHf5fFMvzgJJ a3BC/X5057ZW7vQPg3DauGfpmlcXjTkcw+kfdV9LJ5W1B9oUI186D4oZ+6v13m9g 9w6WOhZBGqJ/l8nf7m4NN67HWK4FwJiWnsZ9lFlbJK4Vczy+qrI5dl3EAFmcJ0KL q/m1+kSM9J7HalVqqASctk8yn64IwG9n+SvgCMZc6jRzo4RSe6O3oeFsMRA7K4Yl Rgoi1x8wIpnD6FkLPhB2ZfhD3+3sMjUdlDlqTyFKuPR2Ip/bPzRNdyhiZ9998GBs m+5qqU+WLj+JfImermWo3cXTQvJTxyc2S4+r+NEC1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelledguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeeinecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Jun 2024 02:39:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 13f85735 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Jun 2024 06:39:09 +0000 (UTC) Date: Fri, 7 Jun 2024 08:39:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Eric Sunshine Subject: [PATCH v6 20/27] revision: always store allocated strings in output encoding Message-ID: <03556233d6296973176a4edbcaffb12746cd2f1a.1717740366.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: The `git_log_output_encoding` variable can be set via the `--encoding=` option. When doing so, we conditionally either assign it to the passed value, or if the value is "none" we assign it the empty string. Depending on which of the both code paths we pick though, the variable may end up being assigned either an allocated string or a string constant. This is somewhat risky and may easily lead to bugs when a different code path may want to reassign a new value to it, freeing the previous value. We already to this when parsing the "i18n.logoutputencoding" config in `git_default_i18n_config()`. But because the config is typically parsed before we parse command line options this has been fine so far. Regardless of that, safeguard the code such that the variable always contains an allocated string. While at it, also free the old value in case there was any to plug a potential memory leak. Signed-off-by: Patrick Steinhardt --- revision.c | 3 ++- t/t3900-i18n-commit.sh | 1 + t/t3901-i18n-patch.sh | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 7ddf0f151a..2ee6886078 100644 --- a/revision.c +++ b/revision.c @@ -2650,10 +2650,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--invert-grep")) { revs->grep_filter.no_body_match = 1; } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { + free(git_log_output_encoding); if (strcmp(optarg, "none")) git_log_output_encoding = xstrdup(optarg); else - git_log_output_encoding = ""; + git_log_output_encoding = xstrdup(""); return argcount; } else if (!strcmp(arg, "--reverse")) { revs->reverse ^= 1; diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index f27d09cfd9..db7b403bc1 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -5,6 +5,7 @@ test_description='commit and log output encodings' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh compare_with () { diff --git a/t/t3901-i18n-patch.sh b/t/t3901-i18n-patch.sh index 4b37f78829..5f0b9afc3f 100755 --- a/t/t3901-i18n-patch.sh +++ b/t/t3901-i18n-patch.sh @@ -8,6 +8,7 @@ test_description='i18n settings and format-patch | am pipe' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_encoding () {