From patchwork Sat Dec 19 21:58:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipunn Koorapati X-Patchwork-Id: 11983725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18219C0018C for ; Sat, 19 Dec 2020 21:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D00A623A23 for ; Sat, 19 Dec 2020 21:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726841AbgLSV7Y (ORCPT ); Sat, 19 Dec 2020 16:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726768AbgLSV7W (ORCPT ); Sat, 19 Dec 2020 16:59:22 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF93C061282 for ; Sat, 19 Dec 2020 13:58:42 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id y23so6936049wmi.1 for ; Sat, 19 Dec 2020 13:58:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=TIr7+Yi44S+nYaB04bW0X7K/x1XckZ7DEkeNRBwS4b4=; b=snDq7U5C4lsEtKn2dqh/reFMsP5ynfOzPYJaGvUB7wXrhSnueZ1lBvGmRsoi2xqyjv dJb3cVIxVuBkIpL2UpUAS0Uz1Qh8lufeEx92IyuXVUXGC/haToURygKcf4e1egB+N9uv oJfGjXeGq5diBxd5M5uGvxRN5vaubNnXsvl1ZrwST2L1y0Er6M6XEc01OcfRCjjFr3/I x2w2JioiEYT8kg3R2ApW80zb8KIEtTDBimghFKqPb72i9Xct3EZj+sKgOKf6Q94zvTnv etDo2o8ogNV1vWKdDqZUlqLYpkEx7J3jQsRBaXSMXA+Z0OisrRPw/Q66GoKxojxlcAou zh0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=TIr7+Yi44S+nYaB04bW0X7K/x1XckZ7DEkeNRBwS4b4=; b=HDpqh1EXxXPxnl7j5umRS1aQ1TO+d/+9X0Z+ycoIoQAbVdGJK1EezQNFVY+a7TD4jB ALgdJ+MaxQG/E7O59qW8wjpyzz2n4pIAZUnXk1LnxN+3GOUsWsliwniLeAngUHd0W/eo bu/h6NmjuB+XljZ2r3fb83ot0mr5lCugHmwDNrpiK79K75z3zfKWbtYAU1M3A1yWHCpD SzvKpwBYEU4b7tgMw+FIn14f6bRgwia0KuEEepqw01pSZ3QKy1t3a/R6qFaGxZmimmHV 7UEZ0qTYPD+7l7St52rcVk3Z57+jQvoN4xrVpQDQl3E2cd75rfRbPIqnX1A7FvJ9Bzg/ KpLw== X-Gm-Message-State: AOAM533GkPEyTQXboWYqtW3zlzkoqjEhAN/Z3/pCerI3HH+psUM/QHMD YmneEvwD7EPmiwgtaXwr6h3ro4kNEgg= X-Google-Smtp-Source: ABdhPJwKsenM2RNYM9KVWkjbJRttZgJY3qtJZdYfdHIn4sbGbq0R2OK1QTPlh1aKqT0Z2rj5KuMfnQ== X-Received: by 2002:a1c:8115:: with SMTP id c21mr9564064wmd.1.1608415119661; Sat, 19 Dec 2020 13:58:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h16sm19840153wrq.29.2020.12.19.13.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 13:58:39 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 19 Dec 2020 21:58:36 +0000 Subject: [PATCH v2 1/2] negative-refspec: fix segfault on : refspec Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nipunn Koorapati , Nipunn Koorapati Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nipunn Koorapati From: Nipunn Koorapati The logic added to check for negative pathspec match by c0192df630 (refspec: add support for negative refspecs, 2020-09-30) looks at refspec->src assuming it is never NULL, however when remote.origin.push is set to ":", then refspec->src is NULL, causing a segfault within strcmp Added testing for this case in fetch-negative-refspec Signed-off-by: Nipunn Koorapati --- remote.c | 10 +++++++--- t/t5582-fetch-negative-refspec.sh | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/remote.c b/remote.c index 9f2450cb51b..cbb3113b105 100644 --- a/remote.c +++ b/remote.c @@ -751,9 +751,13 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite if (match_name_with_pattern(key, needle, value, &expn_name)) string_list_append_nodup(&reversed, expn_name); - } else { - if (!strcmp(needle, refspec->src)) - string_list_append(&reversed, refspec->src); + } else if (refspec->matching) { + /* For the special matching refspec, any query should match */ + string_list_append(&reversed, needle); + } else if (refspec->src == NULL) { + BUG("refspec->src should not be null here"); + } else if (!strcmp(needle, refspec->src)) { + string_list_append(&reversed, refspec->src); } } diff --git a/t/t5582-fetch-negative-refspec.sh b/t/t5582-fetch-negative-refspec.sh index 8c61e28fec8..58b42fabd97 100755 --- a/t/t5582-fetch-negative-refspec.sh +++ b/t/t5582-fetch-negative-refspec.sh @@ -186,4 +186,19 @@ test_expect_success "fetch --prune with negative refspec" ' ) ' +test_expect_success "push with matching ':' refspec" ' + ( + cd two && + git config remote.one.push : && + # Fails w/ tip behind counterpart - but should not segfault + test_must_fail git push one master && + + git config remote.one.push +: && + # Fails w/ tip behind counterpart - but should not segfault + test_must_fail git push one master && + + git config --unset remote.one.push + ) +' + test_done From patchwork Sat Dec 19 21:58:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipunn Koorapati X-Patchwork-Id: 11983727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 234FCC3526D for ; Sat, 19 Dec 2020 21:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E876723B08 for ; Sat, 19 Dec 2020 21:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgLSV7Y (ORCPT ); Sat, 19 Dec 2020 16:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgLSV7W (ORCPT ); Sat, 19 Dec 2020 16:59:22 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA14C0617B0 for ; Sat, 19 Dec 2020 13:58:41 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id r3so6844379wrt.2 for ; Sat, 19 Dec 2020 13:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HpkuCdZdB85B+BmA/yqCf+ZFXqMotDFtVn4WR/mIu+E=; b=YmaPwN60jLJZshmTwhGpxfTv2L5vlywaCoTXZu4PuFOafAZx5B1aqLucAyBNQZt7k1 j25uTxLMBWG5+jiM43iOY69TGpU3LAeDKcXznd0MT1Y62QjN21EOCsXjwdeaaM0UQMSQ 3ihgZLOfYg3CkUJ1Ahj5d8LaFQdsKgZFKBSF2jbGdTXfNySWBG21VDAn77myXdf3p64v xj6U7DFPHZQfPOigomtP795cmroOoTsxKMJluQgE8Pk1x90P/yAlpRvs5+gAwvFE8lL3 Cgl5VsVp29Wlhd8ybOVf8E2nx1gIKXgzFYNgH/NkohVRmthVZzeKN1IkyclADufdCAx1 +u2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HpkuCdZdB85B+BmA/yqCf+ZFXqMotDFtVn4WR/mIu+E=; b=a4WkNud7r0HOdDot9Gyzaon6hYKeHMcNnCyHUlv/LgP67hcPaJb8VW/lk3XlNQifK+ OspO1vMXNUkXFM6B24tnmpMxuvh4aod9bWPeHKisF9vvE8FchwfUxDtZxzFSGet6dWMO aaTA+gh6CtobRpKTilDEk/7QPf447SOfY2CrB57Ul1dzV+sDBMu3otKfgssc+OyAqsn8 lHXOsEIoaQHKFGhZPUIWYLm9SplF1zivD91DSY+aICtqR3fbkgbxiqOX1+KDjUz9ep5m Uh6JjJWwQBQ9wZyoe3bAvqnkPRkO8Bzmsq+Jpb/GUPCbdcL+LBcOS1gkCH+LHwawdssh f/Iw== X-Gm-Message-State: AOAM533R3s7pO2B5yxkP6lfIgDTn34kLpHMKjuWsdTJX3MfxRj19ceq8 XDjnPFHXrvRnpo+ByyaylqScWugx5I0= X-Google-Smtp-Source: ABdhPJyzgK5NQa5U7JGtexdGuDAX2v7k2GUfxgUtDE7SsNICXbM2CKQ59IFjG1SV6GmKU1Ag1SCxqg== X-Received: by 2002:adf:9567:: with SMTP id 94mr11112708wrs.394.1608415120453; Sat, 19 Dec 2020 13:58:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q15sm18150875wrw.75.2020.12.19.13.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 13:58:40 -0800 (PST) Message-Id: <8da8d9cd1c5230aa3a62f1d339c5006d33630edd.1608415117.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 19 Dec 2020 21:58:37 +0000 Subject: [PATCH v2 2/2] negative-refspec: improve comment on query_matches_negative_refspec Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nipunn Koorapati , Nipunn Koorapati Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nipunn Koorapati From: Nipunn Koorapati Comment did not adequately explain how the two loops work together to achieve the goal of querying for matching of any negative refspec. Signed-off-by: Nipunn Koorapati --- remote.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/remote.c b/remote.c index cbb3113b105..6cdaa8da75a 100644 --- a/remote.c +++ b/remote.c @@ -736,6 +736,12 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite * item uses the destination. To handle this, we apply pattern * refspecs in reverse to figure out if the query source matches any * of the negative refspecs. + * + * The first loop finds and expands all positive refspecs + * matched by the queried ref. + * + * The second loop checks if any of the results of the first loop + * match any negative refspec. */ for (i = 0; i < rs->nr; i++) { struct refspec_item *refspec = &rs->items[i]; From patchwork Mon Dec 21 02:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipunn Koorapati X-Patchwork-Id: 11984209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55E0FC433E0 for ; Mon, 21 Dec 2020 04:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D8A922CB2 for ; Mon, 21 Dec 2020 04:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728355AbgLUErS (ORCPT ); Sun, 20 Dec 2020 23:47:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbgLUErS (ORCPT ); Sun, 20 Dec 2020 23:47:18 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F4D1C061282 for ; Sun, 20 Dec 2020 20:46:37 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id r4so9661042wmh.5 for ; Sun, 20 Dec 2020 20:46:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=D6R2xMYBnOCgYtvJdv+7WkxHb2CdaZcBtkWyAtkeR7A=; b=n5cGOfY4tMMlCwW2JC3fWzpkeBIMME/nmhBEbD7GUTtcvBAQKpEaqyX4LOqBGTiemJ umSi3CbhhAbFTqkoLgc+vFpegidpM/MKcfzWsR/WfCMgeAncFlikAUa+WSwLC+K09dRw +Mt4vm1MonKsaRwcMVwkH6YKuvs2JEO4lhRnsLEYl2pXeEiurlg0dqUqqzMS9qDPJ396 ln4NoVHoGniMHALfJAk5SbgJgxJ47U5genWNvlItgXYW8eVf3u8aktiZpcMiQ5RII5Gb WF/0ua1MNsb5LWyps/mJoaR4KUFSGQIwLTHtTpa1yat/1nfx6AKQXaSTNuRx37+PlCxc IW2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=D6R2xMYBnOCgYtvJdv+7WkxHb2CdaZcBtkWyAtkeR7A=; b=U2cVgrj+VxWq3XVkIp7CJHbA7O2+vbi8nrz4Eyh2HstILpZcUDyYLKXghjOONYMmC+ r3hPQIQ+h+rDfJDly2F6mJGVz8/ljeSp4ut3s7K1nUFbbalVyET1rcEcIbbgtJ5nkfay dpK8jzoUjfYhVShZ8TSW0AmpQSKf+3H+uXr3R5Ft7MfJIYa8fc+tr/Je4tKvK/2od3G2 8m8bj6mvVhXogQs0phVYHMpLU3dsR4gCsy7L2sulOduQlJnEISIR5dpfb0ZR8q7x0hty NoYnT3U6w4nYS0VryD5XD2QsmfzEe1poxbwvAha+yC3jlCKSdFJIlTd0u1H8HtxdIdYn Zfmg== X-Gm-Message-State: AOAM532ZF4V+G9ZOm2vQuLm+3PK5+iVcJ9TBtBsaqu1InThvgwehATMt 3HVQEcQIuJ2GMoGclhmUj6Ec42e0a4Y= X-Google-Smtp-Source: ABdhPJzLBUkmuG8phq2YTwtdJcPjDS3UmXZOwBOREbyxFCm7YAJTUY5za9TcNvojwquUZBUgy0hnPw== X-Received: by 2002:a7b:cc94:: with SMTP id p20mr14244212wma.22.1608516324900; Sun, 20 Dec 2020 18:05:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g191sm22937898wmg.39.2020.12.20.18.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Dec 2020 18:05:24 -0800 (PST) Message-Id: <0fd4e9f7459901e6e93bb21c41d04759b40b60c3.1608516320.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 21 Dec 2020 02:05:20 +0000 Subject: [PATCH v3 3/3] negative-refspec: improve comment on query_matches_negative_refspec Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric Sunshine , Nipunn Koorapati , Nipunn Koorapati Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nipunn Koorapati From: Nipunn Koorapati Comment did not adequately explain how the two loops work together to achieve the goal of querying for matching of any negative refspec. Signed-off-by: Nipunn Koorapati --- remote.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/remote.c b/remote.c index 7323694b163..c3f85c17ca7 100644 --- a/remote.c +++ b/remote.c @@ -736,6 +736,12 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite * item uses the destination. To handle this, we apply pattern * refspecs in reverse to figure out if the query source matches any * of the negative refspecs. + * + * The first loop finds and expands all positive refspecs + * matched by the queried ref. + * + * The second loop checks if any of the results of the first loop + * match any negative refspec. */ for (i = 0; i < rs->nr; i++) { struct refspec_item *refspec = &rs->items[i];