From patchwork Tue Aug 13 09:31:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761662 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 274C2189B9A for ; Tue, 13 Aug 2024 09:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541524; cv=none; b=APbMDw7Nibjl25OdmEZ3pfRA8fPRF5sNj+YWqRRNe+NBjyJQ2B5bl2wDet/Dbtc+dqc/oelE4i3UvlxWVk77UhtNcM+QJ5w1VjcX5TNnUfAF+Bi1mfoelwnQl7NRyx1vPhtXn1rryAPeHYGTy5AKircdCfFvc4nrwycJnxKkLog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723541524; c=relaxed/simple; bh=yrlhgSdKEnDhi1HUwtx7k/dXX5LhZXH9LP34Q/lwjIc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sWtxYSrjIawyNZJwXda5Zw/F5v8yFBHs2cdP5Wbnhzj0Xv3gj78rEpB/NgdRoFI9wCoGQ0hK7oq11OSmvlX4XcXToE4f/vLO8lS6wIAQkOfMuMnnbn7u2w8P9KNmOAicC0sKhnm0LmiOIF+iUjtdW821FVtdRfMOTjqsRiDyYi8= 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=KpgEHABm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ckAoQIPU; arc=none smtp.client-ip=103.168.172.156 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="KpgEHABm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ckAoQIPU" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7EEB11151BB7; Tue, 13 Aug 2024 05:32:02 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:32:02 -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=fm3; t=1723541522; x=1723627922; bh=vBXD9cXde1 d+k0rRqwemqouzQf8J3Q5zX7ul7aMo7qM=; b=KpgEHABmD3yVdKQE+CmBBo9GM1 7EBXOw5v89l0eRKfGQVrhljn0FQhMAD/ZVZnluyCiXSCI+kSExWVqZAYNsW89aAt Tz6WH1pEP6D7ks3btATwNoiP94tx7izJYZx7pzG/WldL4UW+ZMMhfBl/m3uOcjMk ujSrCiKcA4H48d9yy5Y/DsP0LbQYoeJYVLUFoGeNZbFq7BKItW4rvDgE0He2u01+ r9jtzGPT1Ko5lHBF8Vq/35cHVdaxXAAnysuIXJzVrxfpE+21YOxHvIw9RoTIi55W bCVePlLejh1iWq9kqNdd4I1nimEBWOcCVBDQBpzrA9v3MmbqMwnP27RgV/Ig== 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= fm3; t=1723541522; x=1723627922; bh=vBXD9cXde1d+k0rRqwemqouzQf8J 3Q5zX7ul7aMo7qM=; b=ckAoQIPU6gI02pzMdvjkHGVUT427vHN+ETnd0TSSs8Wn 5StTV8esP64BAz/kCjfIvPmyMvdBBgEomYBZQpKp9VSqJpYgAa+JIaLc6YcpZ4x5 oqGa9GW8zyHbFiJ4TSdWdAz7j2IqQ1m9PG8UY/PyPWfI8dwiFCxj/j5vDxuQsHHr /qoyXWUE5+2v1gF6lxaMJkd6TXbs6RaKC4cgVA0ass7Ir8eCi4jzzdMUkbLqNmza VyZN3rihJhSBucvNr189cftb/aIFcPFwgfxIsdXFdgh9auPpsCDWCKjbSuOqFUIF 0z5DZ59mLNWIdhme1oUaIGcTZeEWjv3UcHxY3OR1ow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomhdprhgtphhtth hopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepphhhihhllhhiphdr fihoohguuddvfeesghhmrghilhdrtghomhdprhgtphhtthhopehjrghmvghssehjrghmvg hslhhiuhdrihhopdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:32:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e1655c38 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:31:44 +0000 (UTC) Date: Tue, 13 Aug 2024 11:31:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: James Liu , karthik nayak , Phillip Wood , Junio C Hamano , Taylor Blau Subject: [PATCH v3 17/22] diff: fix leak when parsing invalid ignore regex option Message-ID: 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: When parsing invalid ignore regexes passed via the `-I` option we don't free already-allocated memory, leading to a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- diff.c | 6 +++++- t/t4013-diff-various.sh | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index ebb7538e04..9251c47b72 100644 --- a/diff.c +++ b/diff.c @@ -5464,9 +5464,13 @@ static int diff_opt_ignore_regex(const struct option *opt, regex_t *regex; BUG_ON_OPT_NEG(unset); + regex = xmalloc(sizeof(*regex)); - if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) + if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) { + free(regex); return error(_("invalid regex given to -I: '%s'"), arg); + } + ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1, options->ignore_regex_alloc); options->ignore_regex[options->ignore_regex_nr++] = regex; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3855d68dbc..87d248d034 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -8,6 +8,7 @@ test_description='Various diff formatting options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh