From patchwork Sun Apr 21 10:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13637314 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD6E7DDD4 for ; Sun, 21 Apr 2024 10:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695306; cv=none; b=Mc7SYGBDRe398PfisufvZOs1iuns1U6ZWDwXab3MMglG5C6VX4KUO/hclPbJzVKN2d5JSBAdkxtKtA7I1/Q1P6wBfN1qlT4zZ33vTsxTSx+7h2m07bSXii4RLOxMOqM6Y0AvwbveqZV64pEdzhdZxE7oNN9sg84Tep+xQW4kubg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695306; c=relaxed/simple; bh=7EjVL1I+Zdi+UEhdBJwyms4pzpOSS11KZMVvnY48CwQ=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=VR8biQ88mIGk9kX3IEnmFQ+HP/Ggd2lWNB3cYsNUDh9206PomsCfU1oUkc0rJuOnO9jxZ4uqCNR5lBCyxKtXJo+7AGtVHwjttgNvdgg2L1iAvKKUSPeO8bYnGS/LRmn9DmdWJnc9modka6A8FhvzXHoGt6F76piM29CO/SiJ720= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V+L6riBS; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V+L6riBS" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-416a8ec0239so18750995e9.0 for ; Sun, 21 Apr 2024 03:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713695303; x=1714300103; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=j+CjjcIk6rniiMW6tVoAaEk2MlZLZ27JdZoV3ipmpOc=; b=V+L6riBSfP/ZA3JznsdfTXwK82RTch3tKykTfU5IXkTE5hG+PhN1yvr/2eGpQOojSf jT3Z3qhoMygU6H0f2HIJZqTQLbcXWe/5YVbH4pPfplb4B+Excu/pW8anp0AddVCtkh5D zmJJ8PS8cZI5rRRevj/5uI7biMJzBbbv2v2L6pmu1KOPONgmmeB+6QgoPrm5x9ALsiOT v4UC5fkg88c9P1klr2GqvdP07jk1hpMcPgxNh7LItssPV6PBXdYY3bEaVIL8NqR+DAX5 ncUn4IjLfAFZ9KOa/YWMTW490WbF/K/Rc3DLVHpPkkIZgH78H4ir/m84tNcKJqJpPuvn cMPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713695303; x=1714300103; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j+CjjcIk6rniiMW6tVoAaEk2MlZLZ27JdZoV3ipmpOc=; b=Ldv0SRtXKLpphY76Ssv4dWf5FzyoX6MPVECZJAQ7fg2rsFubbrMmudQCeILwnaRS1j ZWEwSrjrggAEm52sAtL9qqjKo7Wtbii3Sp7bFCbneTf/cvKaQqxZDEZfm8NjXPGZQBa3 9+vKv557su4Z9b+1mfeNKcddcU2neX4e5Xl0YxjuXpoLcx5eNCPS55j0I3xmvbyg8/NS p9JjUvDTJLz6ZCPOCUz8V634jrqUUmCNnGPvqlhYojnCbag7ysboemBXvXFGaJJovdn4 G6ZbMjtTgDfj4XHdo1RXvxRV0uzHHnnnEh78YSYsj0n+h1T0Ubxb8l08xFNZzacUJT1/ pmBw== X-Gm-Message-State: AOJu0YxReooutGxyjQ1PONzAfdPRWq/VlJUFh3/VerIIq5unZ7lH18BU ZjZosPuvdxZa6tNTp/GKybFVWLbrjF4Lc3hWvj+Ri5u1WYUDXOQXxrfXfw== X-Google-Smtp-Source: AGHT+IFrOfhw/5g/3JEt4NcbGiDIUKTSjSOR0T/QJJWbi6puBHy3ghChg8GdE9N4vKgQlntuovA5Bw== X-Received: by 2002:a05:600c:4e91:b0:419:f533:ef88 with SMTP id f17-20020a05600c4e9100b00419f533ef88mr2546328wmq.11.1713695303159; Sun, 21 Apr 2024 03:28:23 -0700 (PDT) Received: from gmail.com (145.red-88-13-173.dynamicip.rima-tde.net. [88.13.173.145]) by smtp.gmail.com with ESMTPSA id m2-20020a05600c4f4200b004186eb69a55sm12865786wmq.25.2024.04.21.03.28.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 03:28:22 -0700 (PDT) Message-ID: <8e6ab088-2026-43e7-a869-b1c7185ee765@gmail.com> Date: Sun, 21 Apr 2024 12:28:05 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/4] apply: plug a leak in apply_data From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Plug a leak we have since cfb6f9acc3 (apply: accept -3/--3way command line option, 2012-05-08). This leak can be triggered with: $ echo foo >file $ git add file && git commit -m file $ echo bar >file $ git diff file >diff $ sed s/foo/frotz/ baddiff $ git apply --cached --- apply.c | 4 +++- t/t2016-checkout-patch.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + 9 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apply.c b/apply.c index 34f20326a7..2f752d71a8 100644 --- a/apply.c +++ b/apply.c @@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch, fprintf(stderr, _("Falling back to direct application...\n")); /* Note: with --reject, apply_fragments() returns 0 */ - if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) + if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) { + clear_image(&image); return -1; + } } patch->result = image.buf; patch->resultsize = image.len; diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh index c4f9bf09aa..c40b661ac1 100755 --- a/t/t2016-checkout-patch.sh +++ b/t/t2016-checkout-patch.sh @@ -2,6 +2,7 @@ test_description='git checkout --patch' +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success 'setup' ' diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh index d370ecfe0d..144619ab87 100755 --- a/t/t4103-apply-binary.sh +++ b/t/t4103-apply-binary.sh @@ -9,6 +9,7 @@ test_description='git apply handling binary patches GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4104-apply-boundary.sh b/t/t4104-apply-boundary.sh index 71ef4132d1..dc501aac38 100755 --- a/t/t4104-apply-boundary.sh +++ b/t/t4104-apply-boundary.sh @@ -5,6 +5,7 @@ test_description='git apply boundary tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh L="c d e f g h i j k l m n o p q r s t u v w x" diff --git a/t/t4113-apply-ending.sh b/t/t4113-apply-ending.sh index 66fa51591e..2c65c6a169 100755 --- a/t/t4113-apply-ending.sh +++ b/t/t4113-apply-ending.sh @@ -6,6 +6,7 @@ test_description='git apply trying to add an ending line. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # setup diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh index c86d05a96f..4d15ccd28e 100755 --- a/t/t4117-apply-reject.sh +++ b/t/t4117-apply-reject.sh @@ -7,6 +7,7 @@ test_description='git apply with rejects ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4123-apply-shrink.sh b/t/t4123-apply-shrink.sh index 3ef84619f5..3601c0c5dc 100755 --- a/t/t4123-apply-shrink.sh +++ b/t/t4123-apply-shrink.sh @@ -2,6 +2,7 @@ test_description='apply a patch that is larger than the preimage' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >F <<\EOF diff --git a/t/t4252-am-options.sh b/t/t4252-am-options.sh index e758e634a3..5b680dc755 100755 --- a/t/t4252-am-options.sh +++ b/t/t4252-am-options.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with options and not losing them' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh tm="$TEST_DIRECTORY/t4252" diff --git a/t/t4258-am-quoted-cr.sh b/t/t4258-am-quoted-cr.sh index 201915b45a..3573c9147f 100755 --- a/t/t4258-am-quoted-cr.sh +++ b/t/t4258-am-quoted-cr.sh @@ -2,6 +2,7 @@ test_description='test am --quoted-cr=' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t4258" From patchwork Sun Apr 21 10:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13637313 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C64433232 for ; Sun, 21 Apr 2024 10:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695238; cv=none; b=srvMA41raT5SXPRcD6ew6Gv2wGKYCwli2yAojolV8ndJdJDGDFlG4906tjwDtUHL/QeEpsZvaAEyp6+jGNGXGKkPdWcOLtwcTjZOy/RsYWtQUWEZ9vSujKBZntjlBhaApKd+UFsVREdzfBTePK0MEz4kljfcmmcEiJdRwz5PTZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695238; c=relaxed/simple; bh=Bx/e1YSgVBgEp+9a3/OF/iL+4FfG4owtwI8o7Lwef9E=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=b4O80mqCY3Eo5zTx8NUFDZa/nB60BbxXyRmrnsKMUX5IsdrJfc+5g16bgzVmNTVo6mwQip2nk4/zJuoGBwXV32qusIlzRyuDeNA81WlDNZJ1oAyeDcZqwvA+35wscn1pG7MSAI0k/WoMRpgNjWiuV7R3u509mx3x3T1r0N6kgyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=USxn5kiH; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="USxn5kiH" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-41550858cabso24590515e9.2 for ; Sun, 21 Apr 2024 03:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713695235; x=1714300035; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=vealx12/tXi5ecAQA2l3XhkAR11Ifid72P5fgiHwlUY=; b=USxn5kiHR9gWMJeeB8+L/gQmJ+uYXBjxg91xVUHHUxE5nBBoOLtaWgPR+ztKJgsl3u haelJlKdT1t78zgbS0s7KP9uhnpxdPS6SC3nmlZyDh+oohC5sADjA0GldV2RVFv/GBRx I/hh4o2V0tX8OOPvZIU8tZa8TSs7MnjaM/MJ6BVaucvLjjMzxFedenikDswDUdvdJjm5 pUwSXG9yAM/bsA5dyx1AwSDZTOWbDUXlYh8d0GPfK4kEZjaxfCLtGLv2AkmDOvSw1EaQ FrxzipCTrXMDDoW5hsWG9BadzLHOqp5lkGpqx+pxxa01aT0wuuM19zLPjZp+Hk01yPGF NkGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713695235; x=1714300035; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vealx12/tXi5ecAQA2l3XhkAR11Ifid72P5fgiHwlUY=; b=auhOxpbS30fp9Gwx14R7ppwk7Sa4UenFtiGovssT1P3kv1nV842sZvRVWOUKrqCG1P h5ajqoM4gIf8PNcjbGcg/CufFBI+e83nix/RwIU+MndGpdM59JBR3gw6i0RsTY+Q2LeP 0ko7BBXDfRq3E4ru+7YfIC0XtqN1zBqky72ixypGUwlPO/q6ayO149bFUZQwP9vcGfgI Tjyr/dBsS+SmEAoIne3FrRCvYFEu5y3SxdqVAI7jS1yEVqF0ZaeM9XyEmHbKrHiZx0Ul vkQwqxU98ZR7+uJr5fZvtfpSH34NAsjGq+HBqa8avxmS+UM3N44R9mjDMYruE9IcPioE AHDQ== X-Gm-Message-State: AOJu0Yw44HvvndlUrIQwCdW0pHjSBGAkOOELayATi7dAyHkg45u7O9+e nENjpj1MCqpXyovUO9gN8oxCC3so8wjyyoRcIZwsG4uZziCvDw6RL5hmxA== X-Google-Smtp-Source: AGHT+IGBv66tmmrasjiRM//I66LU4ZApI78HNTXNeCP/B3W+9pLKu5lTwOIeu/4zRSlZ9pennCSuyQ== X-Received: by 2002:a05:600c:4e92:b0:418:f991:713f with SMTP id f18-20020a05600c4e9200b00418f991713fmr4698061wmq.23.1713695234978; Sun, 21 Apr 2024 03:27:14 -0700 (PDT) Received: from gmail.com (145.red-88-13-173.dynamicip.rima-tde.net. [88.13.173.145]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c458e00b00417e5b71188sm12872021wmo.34.2024.04.21.03.27.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 03:27:14 -0700 (PDT) Message-ID: <88b119aa-c1c2-435a-baaa-9422388bf0ec@gmail.com> Date: Sun, 21 Apr 2024 12:27:06 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/4] add-interactive: plug a leak in get_untracked_files From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Plug a leak we have since ab1e1cccaf (built-in add -i: re-implement `add-untracked` in C, 2019-11-29). This leak can be triggered with: $ echo a | git add -i As a curiosity, we have a somewhat similar function in builtin/stash.c, which correctly frees the memory. Signed-off-by: Rubén Justo --- add-interactive.c | 1 + 1 file changed, 1 insertion(+) diff --git a/add-interactive.c b/add-interactive.c index 6bf87e7ae7..e17602b5e4 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -865,6 +865,7 @@ static int get_untracked_files(struct repository *r, } strbuf_release(&buf); + dir_clear(&dir); return 0; } From patchwork Sun Apr 21 10:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13637315 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8ED2DDD4 for ; Sun, 21 Apr 2024 10:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695331; cv=none; b=f2zVnCD0lEqnHsLHVB7hNpCYaQPVkXP6XHaS1a+KLT7Gwbo3mlDWCUTElA3jS+skCw9HJ+UBftwvpr4hyt41fWmbuJSd/uvhh4nGXkSPfAnZeF00tDO1YFwlgq2bvXuGopo4Xbn8v+I4PjYxPm1iwdxBkCRigTDLEiWSIAi3EcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695331; c=relaxed/simple; bh=/gQhFJmvBecJiEHHnRohfuX0TfWh9XSRA8Eo/fgezN8=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=GNlKkoKfgmhiB1vR1QCTOrGHFYIhSHTqwzTZ+PnoR6APMoM+bpNFCI/CuFAQm4Ma+jnaS6ViRdZWgvaHD5p+9B+YMwkE0HM1bcsOWNe4Ytrv38WULE1wo7HoCJBbuGx2Y7QZYPAKANDul7AhwH+RVgf5Yd9yD0EY/gVf28UNXM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lNJIJttV; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lNJIJttV" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2dd717d3753so1843111fa.2 for ; Sun, 21 Apr 2024 03:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713695328; x=1714300128; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=5bSz4nfukv3yJQSA8/NeQrL/gRpdK/EDEQMvpaCDGzo=; b=lNJIJttVB4txKlhgSEc9fTamOFu1kOJPOQY5oiP1tLtQkwb8AkUvxma8HUzfP2KAgG AweO3UcCKFcILjB0PirV0LmNiW0J95UJwrI6w1fzXOTibT5H9txMAy/jDrNxmCQCIid6 TgkPvmDrDQEW4kUOiGswPModrvZIJFgkJvNNKWHnr418zP2Lh2DdJENcVud9/4ved/tQ 5kuCmm/+QPy2V0SV5mwsvpJfzo1lv9uZz6w1Bn+SIFsPuSC4oV/+/Xg4+7yw8LPqswkV 5KQtAkVsJ+39NRmZL3jy5llL4BbfFEp8vPnP6ipUBmqNrCuuDEDMVvuTuTozNOh069wg WhXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713695328; x=1714300128; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5bSz4nfukv3yJQSA8/NeQrL/gRpdK/EDEQMvpaCDGzo=; b=jHcm+aMBM7X0PexMWy5dvKwYNYofwDj5eM8lEaji2AO/D2Ec40KqG3eLmVUTD67ukV EnLfVuG9+w8y0fay34yXoc/oWgQaHyDJpr0FJ/280vTOLySAJqmOiv8jG+GPC5GusUAg FJLUF9l+57aP8AfwmWJBsf8qNvLdYgAF27kTYxhWGAUojsyHLtPUqsPZLih5pWl7piDV tsvVbO9wn4K+PIRjpH1tXzQcRjm/M6DfsioyzeLVp5Z0YQ8j0l6wTLsKIyT/3YtNKcUB SNPp3xkf79Za6OJKpk/L1JQUDkkRPaiyPFEoAWkHDLUOW3p4CHifep8k86ZBKPAgSbMO 2WVA== X-Gm-Message-State: AOJu0Yx0zbWZSWox6fsI0gjxIIOOI5v1XD8Q1v4oE9Feu+2fvoZihW4x 6+rOx3CJCrj6MN1Aof6RC8lsKAL54jMACMtnpkaWCUEGZ4hTX3cchagz5g== X-Google-Smtp-Source: AGHT+IFXJCI25ffUQrj1dM/RJQnq+Ybk53aszil771PeWbDsqfrCI4P7Y9xY5ew0hrJwnSYKT6OgDQ== X-Received: by 2002:a2e:9e03:0:b0:2d8:d8b5:73c7 with SMTP id e3-20020a2e9e03000000b002d8d8b573c7mr3899002ljk.23.1713695327733; Sun, 21 Apr 2024 03:28:47 -0700 (PDT) Received: from gmail.com (145.red-88-13-173.dynamicip.rima-tde.net. [88.13.173.145]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c468600b00418accde252sm12942985wmo.30.2024.04.21.03.28.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 03:28:47 -0700 (PDT) Message-ID: <506130db-63b2-4e83-8545-66a71c728693@gmail.com> Date: Sun, 21 Apr 2024 12:28:41 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/4] add-patch: plug a leak handling the '/' command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: Content-Language: en-US In-Reply-To: Plug a leak we have since d6cf873340 (built-in add -p: implement the '/' ("search regex") command, 2019-12-13). This leak can be triggered with: $ printf "A\n\nB\n" >file $ git add file && git commit -m file $ printf "AA\n\nBB\n" >file $ printf "s\n/ .\n" >lines $ git add -p --- add-patch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/add-patch.c b/add-patch.c index a06dd18985..0997d4af73 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1646,6 +1646,7 @@ static int patch_update_file(struct add_p_state *s, err(s, _("No hunk matches the given pattern")); break; } + regfree(®ex); hunk_index = i; } else if (s->answer.buf[0] == 's') { size_t splittable_into = hunk->splittable_into; From patchwork Sun Apr 21 10:29:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13637316 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58CE4DF55 for ; Sun, 21 Apr 2024 10:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695352; cv=none; b=BTN5HKTXTqBfO7VQ647Ee4xnGKs9wpMk+tebsOOZ+7dcDFUhitTzALXLNYA99CX72pIgd/a3BGUGIid7ld/bF+/uj4XhZAW0LbVD9Yj10GrmL+hZHie3V5no45oBnV1C7YZD+VuZNYq7Q1kE2M4bem53ZVQRw/CAGZIkcn2Mou8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713695352; c=relaxed/simple; bh=MhKIfkMZ7+uq/eLgZuuSOL+TEqUSDvMN0l7FwtvOibo=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=jAcyYViXcTuWsfiXsuAzNbRmt8HQPzTRBWbCAEG3Epy0gXJSRRQaGcFsKf84nWUToJq9aw+2HzB1tZ/FUZ5hO5fJsJfS8pvas01/MJ7Y3piW7HDkMmgcskqTv2hT0UHFKY95mMD1nDrssJXODNKaln/VKLDjxc1FVHPRjudUhCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RWIQ/OyN; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RWIQ/OyN" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-343c2f5b50fso2451987f8f.2 for ; Sun, 21 Apr 2024 03:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713695348; x=1714300148; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xTyAD4nrqXUTF0NKc2JwQEYv+kVRtUAID4yUsg2Utjo=; b=RWIQ/OyN4ovF9RolNX6MA3K1pZFTTNuU7SAIi55zxko44UVXpuy/sPrP100ctj6pcb LWYQD8RM95RHAth5BexDkVGKrz2b0GHM8W3ddtUiNRixx2yl4PHPDu2PfuWbddZ8bBlg P3etvWa9pLJ1jen0Lerh1HU9gBdscVbC6hCFfPNwk5zGHCrKQoWLMRWWUR9SaRQLUFpN GT6fww3AOrVZQ6yrdW8Kk7TggaQfkjU6pFbp9i30CuiTfG8nB5aWVAXcw/RVePTCZ9Bu lkxo+X6bDnKXfccUH0VSBN4ThXSDvy92ZpsyF3WCi/N3M6w+Z1KHkd5AlPqi+TqqTLsD yBTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713695348; x=1714300148; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xTyAD4nrqXUTF0NKc2JwQEYv+kVRtUAID4yUsg2Utjo=; b=T3RBJyueTBvyJbBMaTu4EZePgCrdR9I1jJ+O2T9lzh2xBVY85/HttocJhNLHAW0PCc sGtpdducu324AvWw8O17YkhPzJd5JLef8QKtWZDShzA68Tv1nbtrQPBfTieaPIwy0Csb 9Wpnjawua0tDyZKO0uJnvLZVOnRwsiIO2Lt6MyXQdiuFx/6D9jSNZNrdCH8y/Nd9OblE ApO64fuTaWYi+oGrlrBGutfizaqZFJsjF9tAjRIjMaGr9XkPJ7NdiwoVxMz1IGg6ZNOn UDiMyM2eBqSjy3/1inPfFjeZhuMd/nI4naGTIgqGiFl5U1tpqe0ZZyR9KHWWWu0QuqGt wljQ== X-Gm-Message-State: AOJu0YynIrXqFbdtOcebRsi6v5koBSR+SN46KIHYnOjegh1aEMVQrpw9 12aANxJW6/LcPmDtARWCKQXifb0yDBM1buJD0hTZcko1JhPWSwKMdF9gAw== X-Google-Smtp-Source: AGHT+IH6uYidvPFItbYFZ3re8Dfy2k2uknEB/RgwEULp4xpZBUCW3WkU8fiQytE1mLuNBVto8+pJ9g== X-Received: by 2002:a05:6000:25b:b0:34a:572b:3e15 with SMTP id m27-20020a056000025b00b0034a572b3e15mr3739701wrz.25.1713695348597; Sun, 21 Apr 2024 03:29:08 -0700 (PDT) Received: from gmail.com (145.red-88-13-173.dynamicip.rima-tde.net. [88.13.173.145]) by smtp.gmail.com with ESMTPSA id u11-20020a5d434b000000b0034a2d0b9a4fsm7854367wrr.17.2024.04.21.03.29.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 03:29:08 -0700 (PDT) Message-ID: Date: Sun, 21 Apr 2024 12:29:00 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 4/4] add: plug a leak on interactive_add Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: In-Reply-To: Plug a leak we have since 5a76aff1a6 (add: convert to use parse_pathspec, 2013-07-14). This leak can be triggered with: $ git add -p anything Fixing this leak allows us to mark as leak-free the following tests: + t3701-add-interactive.sh + t7514-commit-patch.sh Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future. Signed-off-by: Rubén Justo --- builtin/add.c | 9 ++++++--- t/t3701-add-interactive.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index ae723bc85e..b7d3ff1e28 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec) int interactive_add(const char **argv, const char *prefix, int patch) { struct pathspec pathspec; - int unused; + int unused, ret; if (!git_config_get_bool("add.interactive.usebuiltin", &unused)) warning(_("the add.interactive.useBuiltin setting has been removed!\n" @@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch) prefix, argv); if (patch) - return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec); + ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec); else - return !!run_add_i(the_repository, &pathspec); + ret = !!run_add_i(the_repository, &pathspec); + + clear_pathspec(&pathspec); + return ret; } static int edit_patch(int argc, const char **argv, const char *prefix) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index bc55255b0a..04d8333373 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -4,6 +4,7 @@ test_description='add -i basic 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-terminal.sh diff --git a/t/t7514-commit-patch.sh b/t/t7514-commit-patch.sh index b4de10a5dd..03ba0c0e73 100755 --- a/t/t7514-commit-patch.sh +++ b/t/t7514-commit-patch.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='hunk edit with "commit -p -m"' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup (initial)' '