From patchwork Thu Jun 6 10:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13688255 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 E2A9514E2C4 for ; Thu, 6 Jun 2024 10:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669764; cv=none; b=gSuycf2OpeMR7nE5vNXbJpfokjz/NRdvxLY16IQ+wfJs1ZyppU4SP/m/tA/uQvei8Tg07++K0P+XOXhje/n2HExI00iTf3FmOpACPmxmgWjD3k5gvsQ5BdzHmY6b6yV9y+RHSc7zdSq8BpyK301yPmar/PK5er9ovp7jyw/E9UY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669764; c=relaxed/simple; bh=RWyD4Us0rSRfPUl5L54Vsl+P8U2Ucl0CEsP7jqZtS9A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YEWSOA6uu4zFow7gZVd8iXcNrxyssIEjWNtFrwSf98PeiCfo302vYb8+FL+wQd4A0gIYoTzdCZi18FCV6FilgufSXnpKL9s0UrB4ymkJ+8Q+2HZZWVjf1sBFRVvqf+K9O8cHUE4fymWkeFgbJ53p8DtdP/55oTAZ0Wv1WYiadkQ= 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=IB4nk6SE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZyNH+DzC; arc=none smtp.client-ip=103.168.172.155 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="IB4nk6SE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZyNH+DzC" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 01A9011401AD; Thu, 6 Jun 2024 06:29:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 06 Jun 2024 06:29:22 -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=1717669761; x=1717756161; bh=vNU9ABrkKa V+XbzzgyUfcSYAKJsi+LkEfGC4o7zAoNY=; b=IB4nk6SESchiwaHZ0hlt2coFoV 8p8UDavhuTFD7/gbjhI+y5gVaPM4QmV0BgoHEM+rXTLWv1En427lmU6dzW4hEVyI lzi3rqh2LnRytjvS/RUkVHbnd2/NnjP2jBY6T8NEW80pBPQUmyNaACkXf7/RnGwq sfKlL4NG9YksLFlMGLrQn4CAnq7Z/y1LWWA+PrVxhmhaV+lSUpLOBvALmM1n6Kqn KDzfc03b/zi2FF3qIjh2G8ub0zIFTeSkOWI/QxhD5OraD2k/K9EzX7CdUgok9C44 13POQbV6mQeaK+PW1pH5YGTAslWkfIkropfDpKzDJ7ojyu1WjmKJCQHYTzxw== 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=1717669761; x=1717756161; bh=vNU9ABrkKaV+XbzzgyUfcSYAKJsi +LkEfGC4o7zAoNY=; b=ZyNH+DzCDrUeYinOUk7fQzIUFjfjPNqrFtvXnTly5qxA r1niDsLFlXyuk1LAOHqif1PLZs6R/Jselx7LcnSpzIGcyp+Kp1VEqRDdUErezAvo +JJzM9DIIs5XFtBNa+lnIrxk61+BjapkC32/RgAQ9+DRtIkXy1HTB4Ix6sa0UHEP iDqLYSoet7bR70f2Et1ZOzL131KvSFPMt4QtL96OsSPeAjHvhYlWJ1ezS9uU2++M Batu3+SCCEVuqomQdihKFT9JZt3mH/KVTam96pu/YmRzBND4JW5ETo3xkN0UpMsL 2vDZaEdaTNo0qO4TV+B5S93RmzJMKukj7CtnehmCxw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelkedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Jun 2024 06:29:20 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c5d3bb45 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 6 Jun 2024 10:28:50 +0000 (UTC) Date: Thu, 6 Jun 2024 12:29:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Eric Sunshine Subject: [PATCH v5 20/27] revision: always store allocated strings in output encoding Message-ID: <38fcea2845b16a6c23a0496330c538501cbc76b3.1717667854.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 () {