From patchwork Mon Apr 22 22:54: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: 13639186 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 A4DB0178CCA for ; Mon, 22 Apr 2024 22:54:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826450; cv=none; b=B1Leq6vv2oOqvYkJDdGAGLmiBumhwEuHw+gNRcOTGy8o1xDb940jQV/E0e58Y7kiJ5n+zioxl2Aq18t0FzYqNj6itahtb3XFFbrih2zT166slyakoX4aOi0cLMV0fsnShN1bx5+7P+C24NrGhsOjyohd59Dqgw8GvMhNe9QsRF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826450; c=relaxed/simple; bh=i8wuzEYS6/StxI9LalXfM+qpMIJ0yIco1Q3UPSerKlM=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=oOQCPFV9G8llIdQ9Uah/pY70zfkqcjdX7YL3a6dtVNqXHluUyVw1suoTR/Zwz09DMN7rQamBvXfAp3hBv4HsJETNE9toNJLttucY1omfgOf73oWa4nHTQ0akvVZ/wHeIhqIAxk1c/VfQ3i1NvA6/Ww4Gm/HhPZbgIcffU/oItjo= 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=T/dJRqBj; arc=none smtp.client-ip=209.85.128.44 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="T/dJRqBj" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-41a442c9dcbso12504035e9.2 for ; Mon, 22 Apr 2024 15:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713826447; x=1714431247; 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=jM9fjBak0nEzn0YlqL+17ArTt1hQ7pQ5sS4xmUmEvqI=; b=T/dJRqBj2eE4j1LlsFb1LUCrQCDIIOX4Y2YqffYLmXSP0YavZRy/9KFV5yI/dIYOlx d6pe4/IibS5NaXFKobT97h8iHiHhxWlW3uB74lU03nm9m+XJHm9gpR1u0ngP5aEHjNMj NImxuGlFOzUGhd+adk6p3l6l3R0FwP0tWZaM4AUnEYVc+9k74AFNbUC4tmeibXSW7sWV 0mtZ6CqZeLKLXvQjy062ccikizgeHYcOx1njJyVkYsvmu/eOkSR3qRFIBfHkWZgQLiOz tgHAaIvij9gnUfIMj4xnhjWGfm6OVjFrKHH8BWU3n+tWR/O/I5/VTyE/8s3NvgEJIa+z mOZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713826447; x=1714431247; 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=jM9fjBak0nEzn0YlqL+17ArTt1hQ7pQ5sS4xmUmEvqI=; b=R1LezAHt8Tnpswve0V9+QnDW1qnWQCKMVZveU9YYDrnmUQz3g8iohqedvFKLHsenMf bEIquth9UKBB2XS+vOCVCHMClwGxCkDBujWpHTGuooZ6KeZptXfW4cq2WFZ7Oo+cf2C0 YR9ghJSsc51VvbUteOW0RYTlMYLf1zr2eClsk/VBkTytmKbui/oeCO05HdTtr0ccqpWT tD5UzZ2BN/c+2i7yiXPJd5dOx+qRKUgFIjYSl6Q9cHRtDFDkkIRFSfWKcCPaWeFHY5px PXPZIG2R35T37PApzBKVjpR6WSZABMZQl8ARSmxSpkcVIj4vhiB99RSL/ZVGaVEdNF3Q P4fw== X-Gm-Message-State: AOJu0YzAQaqErHDNBqyGQVS1BpGoaSDZe7S9edxvbCpWFrxGUAX+pRXk cHcW6ieMruIhszUWZYhycfsG8sHl8Z6kRYq4KPvAJzjraBuL707maRP7Lw== X-Google-Smtp-Source: AGHT+IEn3KP+Ipb0ZJ2XzZlKK7TlDlxQ0QucMeG+ep1mGEjGD6UEDBgsAQZtMkTOJxXTImrmCC7IxQ== X-Received: by 2002:a05:600c:470f:b0:418:c1a3:8521 with SMTP id v15-20020a05600c470f00b00418c1a38521mr8222833wmo.26.1713826446848; Mon, 22 Apr 2024 15:54:06 -0700 (PDT) Received: from gmail.com (247.red-88-14-44.dynamicip.rima-tde.net. [88.14.44.247]) by smtp.gmail.com with ESMTPSA id q15-20020a05600c46cf00b00416e2c8b290sm22082853wmo.1.2024.04.22.15.54.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 15:54:06 -0700 (PDT) Message-ID: <5e97fd0e-8aca-43dd-9f6e-a8cb28fa01b8@gmail.com> Date: Tue, 23 Apr 2024 00:54: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 v2 1/4] apply: plug a leak in apply_data From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> Content-Language: en-US In-Reply-To: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> We have an execution path in apply_data that leaks the local struct image. Plug it. 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 Mon Apr 22 22:54:08 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: 13639187 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 3493A18132E for ; Mon, 22 Apr 2024 22:54:10 +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=1713826452; cv=none; b=PGIBnPQByhjtY8hzvpOBvXNAJyT610U0LFpBdSm5ZAMO3898ej6zbLWDxpAqIfA0p1OnEeimDyeVMSLcl+yeZkktX0369D8QlrQaVnF28+iMIz6wc75ScMiW/XG7zcVyAMuu23Y2Xv+d1UVIzdW0Xv0r2qOuyYNLzCHKgKaFn08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826452; c=relaxed/simple; bh=782ITABcjibzu6XpJ327ueZxKUGUhHkhSwdeziPOGXs=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=S7Vm5FCDPRwKBuokLh+Nc+A9ObShv5M99Ev6QsweSeW48z7vUkXSMi1NAbwR6rum+uDs0novfoSyidHLX7ZGl8zHqF/HbiiYu2k5QgoSyWdykTxxFkD+1P0rc38RcdiQzTO/Fd1Ic7hILlkvu7e2WSmTi8k7kA3FzJUbUlP28Do= 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=CJ73S+g2; 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="CJ73S+g2" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-41a70466b77so9503695e9.0 for ; Mon, 22 Apr 2024 15:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713826449; x=1714431249; 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=x1B9lLTHGH+HLm+8bch2P/Zz1SG5IoHSSc7YI+HONNo=; b=CJ73S+g2zBsRQlVslJ5zDkqEBQf9UJJk/R4mupiuA0OprbL2lXiPdH+0kS/gl4Dqj4 jWXdxeRVqiyO4247JTBNiMTyNrX/ss27GgwkCUL3XMS60SaA7rMWrV/O45UM9kDW5mhI YxnSMDPniMvDp/BDpz2kOyA85uwJRxUvYUAyjD7hU31dpL41O5CwHdsETWwXw+XS24m6 3qh9nAz9pKyiWlW158RuLWVVBWOevss+X8gnewYxp5/4AmHyaWbMOCcz/meFYEFfplsF W0sJd/StKnvqsde3DnqTAAVxSmLe08TjR/xBygPonuI9fYXZhR9dFtnejEpodYAVctHG JS6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713826449; x=1714431249; 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=x1B9lLTHGH+HLm+8bch2P/Zz1SG5IoHSSc7YI+HONNo=; b=M01EveEZD5qy/hj5brF56gfX/yrdImTpCK/3CLkuRSWD88Ih+Ldfzbwffi66SYdARl vqaP0UJNJ47WT0xzSFmMqiR5MEafLlA4NljTEtERPhTmoullTYN2TAEIHiZyDodv/AtX P4In1oieozYhiEnmgAtdDhNJVzisS/VMbSig5weL6iotmfn7LIEH4P7pxJ319Z0yVz4k zuCZ0voEtXdAJa3OrfBTC65VZF26DV3ptcU/Ws3uccTcBKjLHMzs9pIb2zuHjWdFBIMD e4AkbUY7mggsqRLny7VzQsaVc04rmJo7DQy+2cJyKtaiXlgTsH2VC8oG/fj7kBeIyZ4q OGvg== X-Gm-Message-State: AOJu0YwkarTL6JGBgR2EOVJyPby0A0MvhHC/YJ0hOsl6E/xQBC1uXcRp o7WgegSQFwI4cSS1lUmaiOErKdJ+BlwS+kxdlFPEa218s/50q+NyZ1xFSQ== X-Google-Smtp-Source: AGHT+IH1aWfQWQflvkZ1cOnYPtAl2/MnFG2WbjearBGnF1Qds/QCJ23n2DDlm+YDymXvQEpV5kU3gQ== X-Received: by 2002:a05:600c:4e14:b0:41a:aa6:b59e with SMTP id b20-20020a05600c4e1400b0041a0aa6b59emr5505988wmq.5.1713826449491; Mon, 22 Apr 2024 15:54:09 -0700 (PDT) Received: from gmail.com (247.red-88-14-44.dynamicip.rima-tde.net. [88.14.44.247]) by smtp.gmail.com with ESMTPSA id q15-20020a05600c46cf00b00416e2c8b290sm22082853wmo.1.2024.04.22.15.54.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 15:54:09 -0700 (PDT) Message-ID: <791e97af-f233-4c06-9c5b-2b9ff758736e@gmail.com> Date: Tue, 23 Apr 2024 00:54:08 +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 v2 2/4] add-interactive: plug a leak in get_untracked_files From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> Content-Language: en-US In-Reply-To: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> 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 Mon Apr 22 22:54:14 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: 13639188 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 689BC18132E for ; Mon, 22 Apr 2024 22:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826459; cv=none; b=okGhNSqC5PVq4KEyC+dyHsLvhL1Q5uUrlBXTlxsCy4I/4v6MB+HTVxezckrDiHx91t4cxG9k4hNPLy151BPYHFiw+EdxOqg4If7mYdFYKfbIWhOlEdxWJA5RabXPzK2lICwmkmvs4kPhJQZ6iLE140ChfDUTvtmdX9PMrGETt+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826459; c=relaxed/simple; bh=VAooSrui6zEydVaUcelsxciCv+m+WLiivb/rSBMkiWE=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=XRVRWuK7/owC2FJWoqUnkruG6lQfeo/jTN++AvmEvOZEjWl58EXESwqJ4L4NRywuW4G8LDHwqOlqiJnaHqwWPfkXZvp32RHzkrMDahJDgY+6FTZIY+6MoFMOp0WcPR+knhuYM7PRCN2FMoUPGsobz4eNHFBQZ9XUH/790qRFWBI= 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=EtzbLab9; arc=none smtp.client-ip=209.85.128.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="EtzbLab9" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41a77836fa6so9051075e9.2 for ; Mon, 22 Apr 2024 15:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713826456; x=1714431256; 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=7ekfKFOFw7YNc6a9IprhW4SfhR/ROfQIAqDZPjkahrA=; b=EtzbLab9LGKr6iv5tI6LrHaNlJsDAvkehyud5kn5QkKszyK4HWfq6icKO6eZMFi6+l w1z75pC0AV7S4PV7sBVX5xHTgRDzhz5pjJMP6naQ1mcvcOjuc0WQxSHjzr06K2HBA8t1 F8BxnDxaAMLWB6z521zJjUyrzSJUH6sPCP6d/JyUlZ9hXI4/DZAq8AO5kl4oIm90jSeb xq+7ikRcexPmY1fyC8iJzctMuMi9g6d1235meK7IA6ZnQzcAHTbUy0nEjIlCYDxPzbv2 rTxysbBF7YHDINcdcNeuV+/TsVBRFbim+CgV0e6b5/GbOYmuDg8mkMOljAyXopGWhhnH JQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713826456; x=1714431256; 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=7ekfKFOFw7YNc6a9IprhW4SfhR/ROfQIAqDZPjkahrA=; b=xNbfyjVLJ5h/i2/2oLfyoQ54nWvzbBzDCqNUafv6oeG5ddrd9mObuucm01KvWiGQmj zYzdWyxecHeW0Pbj+mRcDTk/viwlDU5wev78QnXhjoBF7u2sxEaO52OaxvbIiQ5gksIV pP8uP/g7G0981ZNnsLi0v7Rix47xnzzOAxvFi2AkB080G35z0oyWcUD82ti0HUZve5Ap OrP3wAyTf+5tnLxasaxaHK67Ts6PqG5t0QniOBnbj62gKvVchM0i+xBmr9MaVkfWeB1e xmsFXn9hvPpLrSIW/1EImuV0eX1mfs2agReI4l5GngAY3IHShNAjyWmCNsYDbKMI84lh wMSg== X-Gm-Message-State: AOJu0YwQWEXX+jwU8bL5FJkulo9ray2M8rg/ZjQAOnG9IwKBOpjMPsvC gyCM3xXIEM/dBUdphHSMqMCWYrf2hjeHyoaU/HhG7me+Vk3nYjZPlJMKNg== X-Google-Smtp-Source: AGHT+IF7SB9t0GaKGFEBI3REMrUEAmSMwJ8p3QgSephbU+Q6pwYDonBKTtWK4kvRaPcb4od5XYTm+w== X-Received: by 2002:a05:6000:ad1:b0:34b:66be:3199 with SMTP id di17-20020a0560000ad100b0034b66be3199mr656651wrb.62.1713826455818; Mon, 22 Apr 2024 15:54:15 -0700 (PDT) Received: from gmail.com (247.red-88-14-44.dynamicip.rima-tde.net. [88.14.44.247]) by smtp.gmail.com with ESMTPSA id y5-20020adfe6c5000000b003436cb45f7esm13016752wrm.90.2024.04.22.15.54.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 15:54:15 -0700 (PDT) Message-ID: Date: Tue, 23 Apr 2024 00:54:14 +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 v2 3/4] add-patch: plug a leak handling the '/' command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> Content-Language: en-US In-Reply-To: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> 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 Mon Apr 22 22:54:18 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: 13639189 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 D9D29181B8F for ; Mon, 22 Apr 2024 22:54:20 +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=1713826462; cv=none; b=OkGq8XT9aAdU2jU2POPtbsj9wT+MCAnx11hrXejyJ+Wm6yh8CHpRaP8Xwf/PdLUFKk59TUo6cNmgcIk5P56RM85Pp74fdawiv0RhdUT3v22w+xL5rH4vgUTV1j6/5dbZ17LlmaJ8ZlIywye/trG1u001MpAM9zuwT92mKB5sEHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713826462; c=relaxed/simple; bh=MAu//HjzaPe2qU7i9dk8VBsvZ9ntU7VIspVpx4Dns50=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=e2J6iUUqCU52IWKBAxzf0vcwA3aS3HqNGVO3lZSiT+ZSjq1F8sqX/8g8o5jv1M+9aA3Z0Yf1C1pVg6SeoZapNw7r83O6KdnSn7RCrIOfwn8EDUHqdzR4iwSC1AvhWc6PXzvuo88d//1bzHAEs7N9YgztrQKjo3prX+bPBvCHiBs= 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=GI51kRJq; 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="GI51kRJq" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41aa45251eeso4094725e9.3 for ; Mon, 22 Apr 2024 15:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713826459; x=1714431259; 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=7KYnuqjfJDqxYkVUF46VHuP2feo9kqLIDVoIS3nW7S0=; b=GI51kRJqSmfkqQvllXeAKmfczdAS4NT9T+0JZrjFmrS+V4fuQABxh7zF7fTxpj8gxd pMOCvX3Bx5u7XbBNo26Q7BHpvKK4Ybuq70wPj1zvs6/MiXCwZR1i9mWDyeobV497jiI6 jUPZtvgfyzg4de3uTwVihtk2U8NhkAiNDkzlt6R2110HHO/kI5hMPKLbnpoQzA+VDgwK fuIGTyMjdS5EEWKV2euCj6IIjKfRYRG1ObojEaDkJXZSWr8Mdc+B6LZpHAaW3AjUcMyr RVADzfC5GkuycTX63Z3VwjZw3ix8hMH2LvnxRvn/jtq0BJPLzPjWynP/l835WzkX3aCm o4lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713826459; x=1714431259; 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=7KYnuqjfJDqxYkVUF46VHuP2feo9kqLIDVoIS3nW7S0=; b=lZ4jn/jIALRV7Ztlhie2H0DhTD79wI5izFzDZYQD093BtJv7CpPTe3Q9Iq/hm/t1hM 5o4P07rCscEns8oIZ7C1i1c5U+CQ+qjj0pKfnvhp0sdH3isgB3+ZaYFfy/+uo1FAkGrg IZNUJWgd62EnScX0BpMkvrkOkcSPkoXXmp6+TfRT22lAQbPFvroUVbr37o5JkHOn/kZx j0zsv9sSXhV1BDuks3d6SCKVXFlUQGBKVPB/Uvvzfgm/BKejI04fPFIZEqnP5xAQhuXm LSVbanhaQJl0cbautotiR02yUAs+7IUPSULrhusV/buim3/mu0Uu5djPlCe89LS+eqpW YVqQ== X-Gm-Message-State: AOJu0YyKuR7XxOjd4PLvT5+1IRbTbVKqH3V3UJWFZG4ldPqdjQ+z4DVe gyl6ydvz8iWSAhgnWvr7L8Sew86OPqJUIMlPMcRduQJoAY5uaNPRUwMtWQ== X-Google-Smtp-Source: AGHT+IGlIB/+wnXeMTfCi6H6HVYryjcMsyuBmmLBp6ugG3zatxTCOU7pUzFjhn/ByY3p3t4VNmqoiw== X-Received: by 2002:a05:6000:e4c:b0:34a:3680:172 with SMTP id dy12-20020a0560000e4c00b0034a36800172mr6521242wrb.16.1713826459184; Mon, 22 Apr 2024 15:54:19 -0700 (PDT) Received: from gmail.com (247.red-88-14-44.dynamicip.rima-tde.net. [88.14.44.247]) by smtp.gmail.com with ESMTPSA id y5-20020adfe6c5000000b003436cb45f7esm13016752wrm.90.2024.04.22.15.54.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 15:54:18 -0700 (PDT) Message-ID: Date: Tue, 23 Apr 2024 00:54:18 +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 v2 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: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> In-Reply-To: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com> 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)' '