From patchwork Fri Jun 16 23:34:03 2023 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: 13283376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD736EB64DB for ; Fri, 16 Jun 2023 23:34:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345766AbjFPXeN (ORCPT ); Fri, 16 Jun 2023 19:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjFPXeL (ORCPT ); Fri, 16 Jun 2023 19:34:11 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C6C3AB9 for ; Fri, 16 Jun 2023 16:34:07 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4f845060481so1796449e87.3 for ; Fri, 16 Jun 2023 16:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686958445; x=1689550445; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=EwPsKY7R0Vwjt6UV+ihATXfK7DdmLjBP90TgwI8Ncyo=; b=LR1aBhuo0y4eLKcsVlhN1HGYr/9u6kSIL8x6ytr602Os34Y5+CNkkmMO8o25J5pytk RDjRoBMTtfBnm9BQvoo5v2nHM5yFjYvIEA/zV1217YuGTc3pZwQ2V4OxD+FCTwBlKweK 9T2mBlGjQuUOOQA6/ztj7wSj5VbsPtCIm06ml96feLAK9LWWpIz/Wb/N9Y5e7SC3Cx0q HsYclwfWrxEfQikVt0yr/5Py9T0Hsc2u3gxWt5l/MpowHjZwOF17zYek2wPLjOQoZfIF wb/ggcuCtJuCh1HmE1UR07XKa+nYOBWUmhV9ooFQYlPgLerGazor7VMNwC+GWyo/Hala oKpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686958445; x=1689550445; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EwPsKY7R0Vwjt6UV+ihATXfK7DdmLjBP90TgwI8Ncyo=; b=MrafAKLWZm7pSvuAY0EqiUuUy7NIOvB4OXwMQs4CfUMnoRdjZMrJfIxSE4z78cUhk4 lI+3dZNDegHDyYmEviaP4ow5Pt5DN0MJf5MykvjbMZY/DEzUqeJytOA7k34vn3OpiCCU r5nZKvbFkfIGRnBJezvLWA9JK7D1mAt5QMpUgDCCiWNHZBvH1htwiK3X4GEpGT1MmVfZ 14xYKkfh2/eMf3tHtF05/19iVlRsNQLLyI/A6gRFUn5C/DNLdFlkuAXUHuF9TDgSFIPu /oAxFFon+w0V17pUO/va9j8zTS2iBD1S7uMdzspxq6fA9IGIN/dquDDPMyeLiXSrehG9 vCwQ== X-Gm-Message-State: AC+VfDzvAT1w4PLZC61ZZQNcKb/fv+lXjHPDIEwh6nzUwJuLUhWMh+X0 P8ieiQVQ8VR7jUmTZBl3sFQ= X-Google-Smtp-Source: ACHHUZ7MSLNJCORT5YjhGsEafGAT/TriB4fp2hB8Y9dIouQywUQTnI6A59VigX39pIkNvfe1A8/sYQ== X-Received: by 2002:ac2:504b:0:b0:4f1:3d6c:d89b with SMTP id a11-20020ac2504b000000b004f13d6cd89bmr2785426lfm.42.1686958445093; Fri, 16 Jun 2023 16:34:05 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id w19-20020a1cf613000000b003f8c5ceeb77sm3355186wmc.21.2023.06.16.16.34.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 16:34:03 -0700 (PDT) Subject: [PATCH v2 1/5] rev-parse: fix a leak with --abbrev-ref From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Jeff King , Junio C Hamano References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Message-ID: Date: Sat, 17 Jun 2023 01:34:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To handle "--abbrev-ref" we use shorten_unambiguous_ref(). This function takes a refname and returns a shortened refname, which is a newly allocated string that needs to be freed. Unfortunately, the refname variable is reused to receive the shortened one. Therefore, we lose the original refname, which needs to be freed as well, producing a leak. This leak can be reviewed with: $ for a in {1..10}; do git branch foo_${a}; done $ git rev-parse --abbrev-ref refs/heads/foo_{1..10} Direct leak of 171 byte(s) in 10 object(s) allocated from: ... in xstrdup wrapper.c ... in expand_ref refs.c ... in repo_dwim_ref refs.c ... in show_rev builtin/rev-parse.c ... in cmd_rev_parse builtin/rev-parse.c ... in run_builtin git.c We have this leak since a45d34691e (rev-parse: --abbrev-ref option to shorten ref name, 2009-04-13) when "--abbrev-ref" was introduced. Let's fix it. Signed-off-by: Rubén Justo --- builtin/rev-parse.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 852e49e340..d2eb239a08 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -156,9 +156,12 @@ static void show_rev(int type, const struct object_id *oid, const char *name) */ break; case 1: /* happy */ - if (abbrev_ref) + if (abbrev_ref) { + char *old = full; full = shorten_unambiguous_ref(full, abbrev_ref_strict); + free(old); + } show_with_type(type, full); break; default: /* ambiguous */ From patchwork Fri Jun 16 23:34:22 2023 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: 13283377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24636EB64D7 for ; Fri, 16 Jun 2023 23:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbjFPXef (ORCPT ); Fri, 16 Jun 2023 19:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbjFPXed (ORCPT ); Fri, 16 Jun 2023 19:34:33 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EB4F3AB5 for ; Fri, 16 Jun 2023 16:34:25 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f8f3786f20so11256865e9.2 for ; Fri, 16 Jun 2023 16:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686958463; x=1689550463; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=MgZNO4N7Lp3aOL0RIWfyplzy3WbAoT4TzJnAt4E1rDw=; b=XeTrYFycksceqDCwuI56fDqADluFJrcofRNk+aab5u2iOxkhtEJAzITOvRGVMcs34O Q1ox57ryzJKcXWQ6kzzIf3NlJjgusabxVVeJbStDbVy7nNozcVJf7aMRKw7eGFu6iQz9 suXaHrzeocMXY0REBQofi9lYqWMvu5tIjaGNycyk56fntngYUfE1qdU5LH7ialw+PILv aEDyiNhpkHN3zUsjO72srFHDPdlhvn+RVD/v7uKuSbgcm2WqBMDlxqkBOL8pg27lY8NI zMzNlWheu/Z9u645cPv/ko0ijcQGnQj/59RECE6nd6N1fCmFUKpuJcCac27YiHSs4R2H ue/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686958463; x=1689550463; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MgZNO4N7Lp3aOL0RIWfyplzy3WbAoT4TzJnAt4E1rDw=; b=e1z7BWUydNWPbo09x06tTnK2oDrCVdQdVHFrrsHXLR/ePBvYXxImyLcG8+WAm/WeGs WeDKZq32JOXdM+4vITohjGaHRCb7G1oy6goZOe7pVmu54GK65P+6Yo5oVW3qQ7UPUfmO NKTG9ltAbWf9N1psKJEiOigw7wRP3WLl/NwkZuB4Wq+kKEg1KPPDD1JXx2jR5e6pivpo fUQ8/mCY/6rcegsXvfetqCeFTshix6zW0tp7xirdEskjP5fh/mt6eha7fZIbvhjQMpF6 RTh8Vhik0q0wMm1m2zx6J6nGustBQtxQ8ZfiEgGTbiMXWPLn4rTJm/Xi7HcBECbDR7OW dU0w== X-Gm-Message-State: AC+VfDyupHFgKtjJxaNNw+fCTe4+8WHkuV3BOwgbKwU5O/N+oCt0RYsW SrKL8wh1CtEoTsF13pmUyQE= X-Google-Smtp-Source: ACHHUZ4MhIzzE5i8/NMwt5obft4nweZ/P0M1g2HR9M3E/Yj8d5CiM2YyG7fLNZn0o+bxHD1c5CrVnQ== X-Received: by 2002:a1c:4c09:0:b0:3f8:fb07:b20d with SMTP id z9-20020a1c4c09000000b003f8fb07b20dmr1902956wmf.2.1686958463539; Fri, 16 Jun 2023 16:34:23 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id h25-20020a1ccc19000000b003f42158288dsm3367850wmb.20.2023.06.16.16.34.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 16:34:22 -0700 (PDT) Subject: [PATCH v2 2/5] branch: fix a leak in setup_tracking From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Jeff King , Junio C Hamano , Tao Klerks References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Message-ID: <7943ec83-8ef3-4397-0d2e-47f47069de16@gmail.com> Date: Sat, 17 Jun 2023 01:34:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In bdaf1dfae7 (branch: new autosetupmerge option "simple" for matching branches, 2022-04-29) a new exit for setup_tracking() missed the clean-up, producing a leak. $ git config branch.autoSetupMerge simple $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch bar local/foo Direct leak of 384 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in string_list_append_nodup string-list.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtinbranch.c ... in run_builtin git.c Indirect leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtinbranch.c ... in run_builtin git.c The return introduced in bdaf1dfae7 was to avoid setting up the tracking, but even in that case it is still necessary to do the clean-up. Let's do it. Signed-off-by: Rubén Justo --- branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch.c b/branch.c index 427bde896f..d88f50a48a 100644 --- a/branch.c +++ b/branch.c @@ -333,7 +333,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref, if (!skip_prefix(tracking.srcs->items[0].string, "refs/heads/", &tracked_branch) || strcmp(tracked_branch, new_ref)) - return; + goto cleanup; } if (tracking.srcs->nr < 1) From patchwork Fri Jun 16 23:34:30 2023 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: 13283378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5B04EB64D7 for ; Fri, 16 Jun 2023 23:34:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345651AbjFPXen (ORCPT ); Fri, 16 Jun 2023 19:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbjFPXeh (ORCPT ); Fri, 16 Jun 2023 19:34:37 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FB23AAE for ; Fri, 16 Jun 2023 16:34:33 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2b448cf5d83so17708121fa.1 for ; Fri, 16 Jun 2023 16:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686958472; x=1689550472; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=dCuO7aOmHMwsehHwZAAEQvDE9lIDN1cQAtYHsydL2EU=; b=F42KoRyqjeYrxMuRlLpJkcQwAfPr5daUCPqxx8IW/0W6hNFCrJIGLO/wJ+hLi2reZi uMniyZx2nLupi1rsZey0exdGK/yamMHmZkMt6m48Cpv36HIZF2MW66hdXvvBcffs2dkN f0OMWGS6e27NQQrfvWQvF/iJg7zQj3DLfh8gPEsP8q2HaH533rW05VLL3FveNZBB+5km bx+M7cpfbEvEPFp8VK84jvljwcE3ejalqpdVC4bTQYCdWdjU4ya9xVDMOH5LFQnf1Gm+ CJABFL0C7to+VoGxkq3N8pDBis/4iNraLvi484X/LAzgNqm5sEPKVOwD8O7VwnFvV5YZ iWBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686958472; x=1689550472; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dCuO7aOmHMwsehHwZAAEQvDE9lIDN1cQAtYHsydL2EU=; b=Zdoo0PShHGbqsbHTE2nEKbXCAxp74KlPOy3tDnAgmkLdzS7wh99BtZTcEXag+gk3QO XYwC8my/BjAUQ6hhzj2IEIRb5DnST7B3MsfVe/Jc2o9mp9DGLQGW3W6OxyE1wj76YFzN QkMe2JYIEi6iRYLJFiFpWUZVfWSdIM5byRQ/rTaAkp3dGtP1pd9ccZfOYqWOcHDaJfYj lyvbK0dYY6YZxKJXgaKwgvvUWPA5bA3JpSkZyZ/t3PdntwfAb4oh0H3lula86RlVVTow cdkbW4s0QD52Tifq4Qbj0BvbXQ7W/gAVtb+A5B2J4I9jaXV6sLPei2GY0wwzO/kuEtSy oubw== X-Gm-Message-State: AC+VfDznl7ZdLuWY7xsnQytviqkO6SpjBgi4B3F5nL8+KEXUV4gwADhn 3S1a7HDdOMxkHMUINUKV9m+4TeLShkg= X-Google-Smtp-Source: ACHHUZ40MJVnrLBRc7D6Qko8Qn2vXliCfy6Sf96iSIi5OS2MFdlwyX5XkbsjWWoMy02jH/1dk20BQQ== X-Received: by 2002:a2e:8ed7:0:b0:2b3:4cb5:ded4 with SMTP id e23-20020a2e8ed7000000b002b34cb5ded4mr3410718ljl.21.1686958471992; Fri, 16 Jun 2023 16:34:31 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id x7-20020a1c7c07000000b003f809461162sm3372488wmc.16.2023.06.16.16.34.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 16:34:31 -0700 (PDT) Subject: [PATCH v2 3/5] branch: fix a leak in cmd_branch From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Jeff King , Junio C Hamano References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Message-ID: Date: Sat, 17 Jun 2023 01:34:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 98e7ab6d42 (for-each-ref: delay parsing of --sort= options, 2021-10-20) a new string_list was introduced to accumulate any "branch.sort" setting. That string_list is cleared in ref_sorting_options(), which is only called when processing the "--list" sub-command. Therefore, with other sub-command, while having any sort option set, a leak is produced, e.g.: $ git config branch.sort invalid_sort_option $ git branch --edit-description Direct leak of 384 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in string_list_append_nodup string-list.c ... in string_list_append string-list.c ... in git_branch_config builtin/branch.c ... in configset_iter config.c ... in repo_config config.c ... in git_config config.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Indirect leak of 20 byte(s) in 1 object(s) allocated from: ... in xstrdup wrapper.c ... in string_list_append string-list.c ... in git_branch_config builtin/branch.c ... in configset_iter config.c ... in repo_config config.c ... in git_config config.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c We don't have a common clean-up section in cmd_branch(). To avoid refactoring, keep the fix simple, and while we find a better solution which hopefuly will avoid entirely that string_list, when no sort options are needed; let's squelch the leak sanitizer using UNLEAK(). Signed-off-by: Rubén Justo --- builtin/branch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/branch.c b/builtin/branch.c index e6c2655af6..075e580d22 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -832,6 +832,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (list) setup_auto_pager("branch", 1); + UNLEAK(sorting_options); + if (delete) { if (!argc) die(_("branch name required")); From patchwork Fri Jun 16 23:34:51 2023 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: 13283379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2858EB64D7 for ; Fri, 16 Jun 2023 23:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230432AbjFPXfD (ORCPT ); Fri, 16 Jun 2023 19:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231781AbjFPXez (ORCPT ); Fri, 16 Jun 2023 19:34:55 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A33F3AA3 for ; Fri, 16 Jun 2023 16:34:54 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f766777605so1793774e87.1 for ; Fri, 16 Jun 2023 16:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686958492; x=1689550492; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=VteroWcXg7OjSzSWfZStLWd+ECcjfqX7/t6DwmOoWdQ=; b=X+oPHq2vmaLWbVNXXMivax0cEiMS3nKB8C1R4bPtMfC0YajIjPLC4hdV++sfa4v0is f4zKlM0wB6uw+mlEUWfuRV3H75A2Sb41VnzGpWAV7bKmTFcVZV2Wt+16iHL73k5diA04 Njc4dxFVnWkVUe1YxMEjw2hZqx7+Qyah4LU1jXH2TL0Q6bxABZcN6aQqg+exA/uvF4G4 ynUBzKmqZ6nv/kZhd3DP4tlxE3alBlhMAxeuYJ5ODDHVjw1NAsJNd5//HzCDICcP0qhz vWnuwj3ikZe1qdt5IqPTVSeF03lqazv3VT05PTd8TDGmWmiuUwIVpkFamq7w5HQ2DJ5/ 7Owg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686958492; x=1689550492; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VteroWcXg7OjSzSWfZStLWd+ECcjfqX7/t6DwmOoWdQ=; b=UluZFxU24p9F3J+2y3TqO4O25WoSRbtzDwRXAUIkJohPKoyIR1qCKljokR9Km38BE/ VeHkkzfqCJtnlKh8HC8+RcbJU+FjKundWnjFM2dxbdWRFe1fH2KIHlShMK8H1NOHKo4C JSl7DHIIJhKbUz28OPih26sVz95sXLZfKf6R74Fmdm3Zr4Li2An6C2CaCEs5P+c6D2vc 3T47gWhY2Ji+tZuT+MiY0DOKWKHyoTM7a4JcoClUry9SZzbzFzkRGgH7UAMVIctfdtI6 3bZbiefpeigSSqj57jUZFaH1RbBm/bwTPJpYgVLux8CH2Tyo/grtV8OuQF+GK/Rd2Nci Sflg== X-Gm-Message-State: AC+VfDww/UlX8X5pC3OqMBswTWFPDHctn93xzzkK7G2gZ6TYHa/Lwvxq EieV1B+lATQoxUP5O70T9SmsiawMs8E= X-Google-Smtp-Source: ACHHUZ4zlClulfszzJR2WZSArqVSi86NesG66F7AD9VaZxPn0psTNzj0cC+bc1MQXgIuKhKkIlACCQ== X-Received: by 2002:a19:9118:0:b0:4f8:46a6:958c with SMTP id t24-20020a199118000000b004f846a6958cmr2236556lfd.18.1686958492515; Fri, 16 Jun 2023 16:34:52 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id l5-20020a1ced05000000b003f70a7b4537sm3368848wmh.36.2023.06.16.16.34.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 16:34:51 -0700 (PDT) Subject: [PATCH v2 4/5] config: fix a leak in git_config_copy_or_rename_section_in_file From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Jeff King , Junio C Hamano References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Message-ID: Date: Sat, 17 Jun 2023 01:34:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A branch can have its configuration spread over several configuration sections. This situation was already foreseen in 52d59cc645 (branch: add a --copy (-c) option to go with --move (-m), 2017-06-18) when "branch -c" was introduced. Unfortunately, a leak was also introduced: $ git branch foo $ cat >> .git/config < --- config.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/config.c b/config.c index 39a7d7422c..c5f4b59ef3 100644 --- a/config.c +++ b/config.c @@ -3140,37 +3140,36 @@ static int write_error(const char *filename) return 4; } -static struct strbuf store_create_section(const char *key, - const struct config_store_data *store) +static void store_create_section(const char *key, + const struct config_store_data *store, + struct strbuf *sb) { const char *dot; size_t i; - struct strbuf sb = STRBUF_INIT; dot = memchr(key, '.', store->baselen); if (dot) { - strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key); + strbuf_addf(sb, "[%.*s \"", (int)(dot - key), key); for (i = dot - key + 1; i < store->baselen; i++) { if (key[i] == '"' || key[i] == '\\') - strbuf_addch(&sb, '\\'); - strbuf_addch(&sb, key[i]); + strbuf_addch(sb, '\\'); + strbuf_addch(sb, key[i]); } - strbuf_addstr(&sb, "\"]\n"); + strbuf_addstr(sb, "\"]\n"); } else { - strbuf_addch(&sb, '['); - strbuf_add(&sb, key, store->baselen); - strbuf_addstr(&sb, "]\n"); + strbuf_addch(sb, '['); + strbuf_add(sb, key, store->baselen); + strbuf_addstr(sb, "]\n"); } - - return sb; } static ssize_t write_section(int fd, const char *key, const struct config_store_data *store) { - struct strbuf sb = store_create_section(key, store); + struct strbuf sb = STRBUF_INIT; ssize_t ret; + store_create_section(key, store, &sb); ret = write_in_full(fd, sb.buf, sb.len); strbuf_release(&sb); @@ -3833,7 +3832,9 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename output[0] = '\t'; } } else { - copystr = store_create_section(new_name, &store); + strbuf_reset(©str); + store_create_section(new_name, &store, + ©str); } } remove = 0; From patchwork Fri Jun 16 23:35:00 2023 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: 13283380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCC57EB64D8 for ; Fri, 16 Jun 2023 23:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjFPXfP (ORCPT ); Fri, 16 Jun 2023 19:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbjFPXfM (ORCPT ); Fri, 16 Jun 2023 19:35:12 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5184E3AAD for ; Fri, 16 Jun 2023 16:35:03 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f8d258f203so10371565e9.1 for ; Fri, 16 Jun 2023 16:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686958502; x=1689550502; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=cw2ANqhRYJm1W1XPiRMKYg1p8yXdsm1zX4nKMtHqOHk=; b=LfVX8ZaQ9NLP5uQ/QYuxJnKUJQLzxPn21JOBbap4cdiofGQXPrvVe51oRkoNL6m7vx GDN/Fx9I3bfS0RA3RhJReclaFl14LkxtSwOJU+L+dxaR65zmBaYFZhd2/PbwXhMMNMEK TcF3nVcuPtXUjr1L/zmYToGmR+uKv3BKrCEE8r+EIKeuH36b5WlfnFe1rFsK7ADGKw8B 1WuWQQGlNFa3+Do6RIDZjyiuJIosfC0PNS+heDqKoH4jMBWTnfUXA/DodQNo9o7HIdDM N3Pto2z6kS1XCp5V9eopW5B6wPxCg6qV/Y0Ts9dmE/2zCm93BruWVvTPkBn3luixgndh uyJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686958502; x=1689550502; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cw2ANqhRYJm1W1XPiRMKYg1p8yXdsm1zX4nKMtHqOHk=; b=QRS3e/WdGYu8+SYKityBLC9Pyw25yIXo+kD8o4W9F/NHgw5VTj9YP9h46HnzO0PRuH +yyjCcf8wIc+VIcOLPCTuO8QR/XqGx3YFrix+btEEiDpYPqaik3YqsdrTLZBjrEsChvR le6VSshrZeKXH1cKCycXOvSZGPP5HRKLZkVLBbUmWqEZRiGrlNLMTRyCa4/icGAFqnda 9mpHlGvCK/eoALTjfz40NNF3StQp0CdHPnySM/iJPKzavReDgGQ0XtBtQzKgi6d12VPU d7x/+qyB9Bk8kUx4NoSJxYY3A31F+ohrov0ht2pOCawBzOxcTkxT6ciZsWPtF/KgmCdE E9Dg== X-Gm-Message-State: AC+VfDxhcMmVKVAkdoB+1lfQo4SpLS4zlGXpmQsxaZcXGCGrtS8iLmT3 506t6JYCRkOYty0C7hhsqMg= X-Google-Smtp-Source: ACHHUZ43HfgG+jJrlLYdywA59KLAoJLlOlrMQlE7GpymhmvWVr6zoJIvtC2F0t8WHGQwuE1JrCMi0Q== X-Received: by 2002:a7b:ce8a:0:b0:3f7:e7d5:6123 with SMTP id q10-20020a7bce8a000000b003f7e7d56123mr2564942wmj.41.1686958501647; Fri, 16 Jun 2023 16:35:01 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id v25-20020a7bcb59000000b003f819dfa0ddsm3354880wmj.28.2023.06.16.16.35.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 16:35:01 -0700 (PDT) Subject: [PATCH v2 5/5] tests: mark as passing with SANITIZE=leak From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Jeff King , Junio C Hamano References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Message-ID: <66aae5a7-a2a2-2297-4249-d22fd070e91a@gmail.com> Date: Sat, 17 Jun 2023 01:35:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <5650c4ed-cec0-d11e-4f68-1661b3638786@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The tests listed below, since previous commits, no longer trigger any leak. + t1507-rev-parse-upstream.sh + t1508-at-combinations.sh + t1514-rev-parse-push.sh + t2027-checkout-track.sh + t3200-branch.sh + t3204-branch-name-interpretation.sh + t5404-tracking-branches.sh + t5517-push-mirror.sh + t5525-fetch-tagopt.sh + t6040-tracking-info.sh + t7508-status.sh Let's mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promptly any new leak that may be introduced and triggered by them in the future. Signed-off-by: Rubén Justo --- t/t1507-rev-parse-upstream.sh | 1 + t/t1508-at-combinations.sh | 1 + t/t1514-rev-parse-push.sh | 1 + t/t2027-checkout-track.sh | 1 + t/t3200-branch.sh | 1 + t/t3204-branch-name-interpretation.sh | 1 + t/t5404-tracking-branches.sh | 1 + t/t5517-push-mirror.sh | 1 + t/t5525-fetch-tagopt.sh | 1 + t/t6040-tracking-info.sh | 1 + t/t7508-status.sh | 1 + 11 files changed, 11 insertions(+) diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index cb9ef7e329..b9af6b3ac0 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -5,6 +5,7 @@ test_description='test @{upstream} syntax' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index 87a4286414..e841309d0e 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check() { diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh index d868a08110..a835a196aa 100755 --- a/t/t1514-rev-parse-push.sh +++ b/t/t1514-rev-parse-push.sh @@ -4,6 +4,7 @@ test_description='test @{push} syntax' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh resolve () { diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh index dca35aa3e3..a8bbc60954 100755 --- a/t/t2027-checkout-track.sh +++ b/t/t2027-checkout-track.sh @@ -5,6 +5,7 @@ test_description='tests for git branch --track' 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/t3200-branch.sh b/t/t3200-branch.sh index 98b6c8ac34..daf1666df7 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -8,6 +8,7 @@ test_description='git branch assorted 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-rebase.sh diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh index 3399344f25..594e3e43e1 100755 --- a/t/t3204-branch-name-interpretation.sh +++ b/t/t3204-branch-name-interpretation.sh @@ -9,6 +9,7 @@ This script aims to check the behavior of those corner cases. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh expect_branch() { diff --git a/t/t5404-tracking-branches.sh b/t/t5404-tracking-branches.sh index cc07889667..51737eeafe 100755 --- a/t/t5404-tracking-branches.sh +++ b/t/t5404-tracking-branches.sh @@ -5,6 +5,7 @@ test_description='tracking branch update checks for git push' 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/t5517-push-mirror.sh b/t/t5517-push-mirror.sh index a448e169bd..6d4944a728 100755 --- a/t/t5517-push-mirror.sh +++ b/t/t5517-push-mirror.sh @@ -5,6 +5,7 @@ test_description='pushing to a mirror repository' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh index 45815f7378..3a28f1ded5 100755 --- a/t/t5525-fetch-tagopt.sh +++ b/t/t5525-fetch-tagopt.sh @@ -2,6 +2,7 @@ test_description='tagopt variable affects "git fetch" and is overridden by commandline.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_clone () { diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index a313849406..7ddbd96e58 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -5,6 +5,7 @@ test_description='remote tracking stats' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh advance () { diff --git a/t/t7508-status.sh b/t/t7508-status.sh index aed07c5b62..4c1f03e609 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -5,6 +5,7 @@ test_description='git status' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh