From patchwork Mon May 18 15:47:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C44F1391 for ; Mon, 18 May 2020 15:47:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C71A2065F for ; Mon, 18 May 2020 15:47:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I2Kf3/w8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728201AbgERPrh (ORCPT ); Mon, 18 May 2020 11:47:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgERPrg (ORCPT ); Mon, 18 May 2020 11:47:36 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45F62C061A0C for ; Mon, 18 May 2020 08:47:36 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id fb16so4884690qvb.5 for ; Mon, 18 May 2020 08:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hxclQLbBSUal7Gbbwbp5s1iq2t0j8ZwEi3scAMADpQc=; b=I2Kf3/w8eWt9TSLTXnrYqD+80+xw8zD00j5KUDs/gHkn9+Y+i/edUxLgtHMUtahCd7 BOCx8bSz0yMv77a288dqXFEjHz9o3AqO+d1ClRgRPN7twUrZ5WMHXSI7hGwfUlcqC69B n2qzKono2Y7P3Bouax1TnyKEXTruRwg5S9nyNfdRPs2TY7m4Cs+jEJhcWiXomNs2x0EA 2QJkssoX03g+G0fgvcYqNR//xU1TKTvHrJsi3zYUTn+fcMhgsTd1jR2nodXbvk6PigRh vcJfaj9G9TJByWPPMfND4tqz63rPEgJFJZrCkq1RRlM7O4ODWnHHbdOjYv7Tf2dK8Xhk 937A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hxclQLbBSUal7Gbbwbp5s1iq2t0j8ZwEi3scAMADpQc=; b=GVb2dVfQtGA/zqRF5/ka5UnJloVp25pn+GhNItLg13VwdlhK14foS1zJtLyy7scolJ f0QfyrMa6QrJqLJLDmEZ+UNDe0+nYcKhBxJn2yBY3+F5YBIKosBWuYcmBSBRv2WgmrCD ck29Wv86FlSe4dTtOOZGQb6X8NAa0pwonMhIjb1I1FeirPead9qZVZ+q0sjTfUg/piXz Y9LN8XDyVm9qWn7szBLXVnF4s+JCs5w4QLF3p10r4YUWDokmHkeLNGgRYqEwvYzBavdI HcD/NtW0ohyBzXpyRocaycDJdHeLWwerrZ8CcpVFyFvPH0TrnZ09eOopGWY1BDMVh4Bw 8SYA== X-Gm-Message-State: AOAM53246kS49mpyEPCnvab08ZNrDmmMiA4qZB3yiDFNIip7gfOoANdd gVoRkjfzDd6FmcGUKtSnfn+jZPre X-Google-Smtp-Source: ABdhPJwn+ns+6TiX+TjtrfSMEr2HjDrvaoOQn21ceISQw18gUvbsZ2Qn0V5+/oo9KQu1R7zj7WMTcg== X-Received: by 2002:a0c:e947:: with SMTP id n7mr17334498qvo.165.1589816855204; Mon, 18 May 2020 08:47:35 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:34 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 1/7] remote-curl: fix typo Date: Mon, 18 May 2020 11:47:18 -0400 Message-Id: X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Denton Liu --- remote-curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-curl.c b/remote-curl.c index 1c9aa3d0ab..6844708f38 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -643,7 +643,7 @@ static size_t rpc_out(void *ptr, size_t eltsize, return 0; } /* - * If avail is non-zerp, the line length for the flush still + * If avail is non-zero, the line length for the flush still * hasn't been fully sent. Proceed with sending the line * length. */ From patchwork Mon May 18 15:47:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555585 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E646F13B1 for ; Mon, 18 May 2020 15:47:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5AC02065F for ; Mon, 18 May 2020 15:47:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ECX56nhO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728298AbgERPrj (ORCPT ); Mon, 18 May 2020 11:47:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgERPrh (ORCPT ); Mon, 18 May 2020 11:47:37 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48E3AC061A0C for ; Mon, 18 May 2020 08:47:37 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id p12so8404785qtn.13 for ; Mon, 18 May 2020 08:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RFan4SxK9IYM8JwqCj6zEhODFuYsjYeefwOc2HlU8gU=; b=ECX56nhOsfs11x/oqzEoLl2qFbDsyEUAH7PnWfB4U3xSaCnBUiN23cNKt4ZuhhwNR0 6EU+7x3d/1wq+o49EeiqvHGw7FzEx0HvFvIlHL7eWoCUBEyVTjYQxezP3JFaqZAy2e1g mdSWzp6gcE17yfJTk5WIULey2I6du95iyJHuku5vcSPgIf5E0W568/Zkq/pxypx1scyu Spq0nG4CXEvAbcredi3xxrK4cPWH8VEe2cPFzjvhZy664APDFRVfr7pOWVhSOc+lS+7M Gj0OEPwdxr3uPp7dbVLmv4sfP4c8Y2kStCeIO66K/58ln32SEMocAHtdxNSUo65XEKjO 53eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RFan4SxK9IYM8JwqCj6zEhODFuYsjYeefwOc2HlU8gU=; b=MTORxLQ9JhyP7uURUnkrQK26SrD9czq1AO93H30hSNvFN1u67J/x0/0yKbzHGgR1LP 6rVHdXZ5phcPlg6h4ANum9Gqo2ybuyxN3TQ9RxDM9ZMZ2n4P8JT7Zv32iobzObkXmU2e 1wD4IdFK8AYd9lVnoc66BAg6otVsaxACF554bPItP9NArBl0ezVUYJUJeoDzZOddwqrz YIKX1FM16nzESWRZKCy/nQIs4FQwsylvynGjDEl3+eGL/jKs8h2LJIGBkZsRGnNyye08 cUQd1D3JpEyjI1+2aaAkLrtXp62ZYJlX5lxroT2Xp8NqEI0z/zilSUEejCVjrVMr4OB3 G4qQ== X-Gm-Message-State: AOAM531bkDj/CslH+eTUJu2CwyI7jA0Q4Shh2vx18uC3roH367y5iXst T9Li5ixc2x6P4CEhS67avgIGg7oC X-Google-Smtp-Source: ABdhPJx8IqSFSwsNCdhQ69UetduGOnNrlOaZnbL1y/KevrKn8mqn1pR6ZvYOUHw/sBzsRj2JIUhL+Q== X-Received: by 2002:ac8:100b:: with SMTP id z11mr17420317qti.157.1589816856399; Mon, 18 May 2020 08:47:36 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:35 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 2/7] remote-curl: remove label indentation Date: Mon, 18 May 2020 11:47:19 -0400 Message-Id: X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the codebase, labels are aligned to the leftmost column. Remove the space-indentation from `free_specs:` to conform to this. Signed-off-by: Denton Liu --- remote-curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-curl.c b/remote-curl.c index 6844708f38..da3e07184a 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1276,7 +1276,7 @@ static void parse_push(struct strbuf *buf) if (ret) exit(128); /* error already reported */ - free_specs: +free_specs: argv_array_clear(&specs); } From patchwork Mon May 18 15:47:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C99E9913 for ; Mon, 18 May 2020 15:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B229720657 for ; Mon, 18 May 2020 15:47:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s5QiX2nk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728333AbgERPrk (ORCPT ); Mon, 18 May 2020 11:47:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbgERPri (ORCPT ); Mon, 18 May 2020 11:47:38 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E283C05BD09 for ; Mon, 18 May 2020 08:47:38 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id i68so8453911qtb.5 for ; Mon, 18 May 2020 08:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=94DHJmUmWPWRI+eSWR3V3Az6QdLbgc8wyDcHm3HccrI=; b=s5QiX2nkh4dELvorLmoLIFp5agX7BqwwQYjQ8WFl++yk8cKFC12VwI5oorJpFlSJ4/ di63Q3nNpVzzhdyIbbum0PIdlkRxl/IXlagR5QD0ZA0eQ9GzicmuHpTneS+eSgIhKsJo tAcK3YZYiYGSM2C4HGkDvEDPpA9dXvCkkmJ5jkUydfLWex4PI1Et+v8C1s+0HdiwJsCP mJ3Gi4RCD4CuiX/lvS86X7stRPzysWFZZrvEvA7AFkIuKS6lWnUKergzEg+X5ElueuG8 wpMFc6bSP4rLHdsZ4GVZZLLmd6Y31BkS2IOYps6fwtM4JBs3+IUjR+QCUUjbAHxXz4ZF Enmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=94DHJmUmWPWRI+eSWR3V3Az6QdLbgc8wyDcHm3HccrI=; b=uGPEYgegyjN0C2zXIkUZ6ojM4x13vPtIqk0QKpDRWtwYjzfHZXZCURx4vM6mhONWGY NFh04B7HaejwHCht2dGwByoGhNPxiRlSl6AmPKX0ZiyVDq9olNpsOIOrooCs2WxFmf74 /I4OhmolO/rmoKyVIw5pkmJQLRk6ag3NFMQuzm7XajuqrA0weDd3jHhCOA9zkNlPSlao Xu2fCv2ZoIkAAQdTMHNgIU3GaQG0iO/D7EdSfZj2fPg4dDqxRexfhoOfL0uCSWregPGg rselEl5TXZUJ9OFAYYWE7NyMRC4ISgdXjiFtlI9ifJFDK0l+eRYYuhzd45y2R97Pr00k DY0g== X-Gm-Message-State: AOAM531Y7Z9d2TRg7oiFUEumMK0qq7pvL+hWZwx+ljt6I8rKJ1AF6nj7 jJnLrmknPoIEcRMF0SEOODzmjGx+ X-Google-Smtp-Source: ABdhPJy2Edgi1YaS7bumYTbsYVkWejUJxm94GlvAKyzZVBc2s3v0GOND9qIovH+dcJyYwToCnJDVLA== X-Received: by 2002:ac8:4906:: with SMTP id e6mr17451166qtq.39.1589816857315; Mon, 18 May 2020 08:47:37 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 3/7] transport: extract common fetch_pack() call Date: Mon, 18 May 2020 11:47:20 -0400 Message-Id: <3a42575bd5d124b6b2e536b1511107ebf5ec1091.1589816719.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the switch statement, the difference between the `protocol_v2` and `protocol_v{1,0}` arms is a preparatory call to die_if_server_options() in the latter. The fetch_pack() call is identical in both arms. However, since this fetch_pack() call has so many parameters, it is not immediately obvious that the call is identical in both cases. Extract the common fetch_pack() call out of the switch statement so that code duplication is reduced and the logic is more clear for future readers. Signed-off-by: Denton Liu --- transport.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/transport.c b/transport.c index 15f5ba4e8f..a6002e502f 100644 --- a/transport.c +++ b/transport.c @@ -371,22 +371,19 @@ static int fetch_refs_via_pack(struct transport *transport, switch (data->version) { case protocol_v2: - refs = fetch_pack(&args, data->fd, - refs_tmp ? refs_tmp : transport->remote_refs, - to_fetch, nr_heads, &data->shallow, - &transport->pack_lockfile, data->version); + /* do nothing */ break; case protocol_v1: case protocol_v0: die_if_server_options(transport); - refs = fetch_pack(&args, data->fd, - refs_tmp ? refs_tmp : transport->remote_refs, - to_fetch, nr_heads, &data->shallow, - &transport->pack_lockfile, data->version); break; case protocol_unknown_version: BUG("unknown protocol version"); } + refs = fetch_pack(&args, data->fd, + refs_tmp ? refs_tmp : transport->remote_refs, + to_fetch, nr_heads, &data->shallow, + &transport->pack_lockfile, data->version); close(data->fd[0]); close(data->fd[1]); From patchwork Mon May 18 15:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555587 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1DA513B1 for ; Mon, 18 May 2020 15:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7E7120657 for ; Mon, 18 May 2020 15:47:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TyM5MO7s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728348AbgERPrl (ORCPT ); Mon, 18 May 2020 11:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgERPrj (ORCPT ); Mon, 18 May 2020 11:47:39 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4133C061A0C for ; Mon, 18 May 2020 08:47:39 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id f189so10538738qkd.5 for ; Mon, 18 May 2020 08:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MkYUT5SwuCNrZz5COB4j4PBTSRC/ZKKDjb8W0WB+11w=; b=TyM5MO7sgTehvYtSOg+0fNywdDr/CCk+Bxh9ltVVxMCElDpSxrYRJGnXsTBQO6yzOF c95vbybf0sW8sco3/GigkRKkwsVFkMQmxrxvDhj2IT/8GY9ZJB9hak9uBnoKVZwRimzA Jzcvdxs9EGrmE3h65GmgIMvc/bAoXOoXBzF/YQoyoP0WhsU/+WAitjex0D/YXKdkR1Wy 808YbHrhwas6eL7no2HTD/xiSbwU98eUHShyuc0TPyejEauZXzzkbLbUlmZ+jgjsjc21 czmYVKkHMUvTStMLmt9niYczwSzfk4R/+R16SJrj1Ng8c+vXhLY6/1w06bwWiZlNh4VM qqlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MkYUT5SwuCNrZz5COB4j4PBTSRC/ZKKDjb8W0WB+11w=; b=e8AAC65cykduZxdRqNs4xHLNsfYvCYcw15/HTMNLxudjUMQWMeXYIKevS3NgXuu1Qs e2rdL0kMxRA8bfpZ5BZ89JzE0l6MTJA44VIlKrAXGbCSZgu7FNT0bwl2x3ROOHebx/xk +cPGTe7QxAhs11itXK3rEsYJXWAAvfmG+R1aRW1HAYvnmZCbe16VrXubUQ64fsdPbIh3 dwZckmjsPs4VigeuTYZNhKYpuDllrRR9NzU9cGhKFyqtpkD4qxizA3wHcxeCzkCBgKrW DZs0H+df1xfsk6+zhuAgO5K4epELs+bPaFHdDhVgXrXRAyXwf1VE4OdJqq5y0Di+dU8u SDsg== X-Gm-Message-State: AOAM5308IpJU7zLIESVvsjTXTvjJXx5bbkP71wXESFe6U3NGQxbKJ4jg mCfI6+6iMnL+5ORGyWQ3PXGBM2GT X-Google-Smtp-Source: ABdhPJwv0+4INkpdS18bLA7a+nOGVM1rctfHVEMCXa1TmoJTUWfLILV181sbIJJEDIJLCMESEdWEAw== X-Received: by 2002:a37:9f4a:: with SMTP id i71mr16631750qke.281.1589816858636; Mon, 18 May 2020 08:47:38 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:37 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 4/7] pkt-line: extern packet_length() Date: Mon, 18 May 2020 11:47:21 -0400 Message-Id: X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will be manually processing packets and we will need to access the length header. In order to simplify this, extern packet_length() so that the logic can be reused. Change the function parameter from a `const char *` to `const char linelen[4]`. Even though these two types behave identically as function parameters, use the array notation to semantically indicate exactly what this function is expecting as an argument. Signed-off-by: Denton Liu --- pkt-line.c | 2 +- pkt-line.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkt-line.c b/pkt-line.c index a0e87b1e81..5c3b4539b5 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -306,7 +306,7 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size, return ret; } -static int packet_length(const char *linelen) +int packet_length(const char linelen[4]) { int val = hex2chr(linelen); return (val < 0) ? val : (val << 8) | hex2chr(linelen + 2); diff --git a/pkt-line.h b/pkt-line.h index fef3a0d792..de81776a7a 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -74,6 +74,15 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out); int packet_read(int fd, char **src_buffer, size_t *src_len, char *buffer, unsigned size, int options); +/* + * Convert a four hex digit packet line length header into its numeric + * representation. linelen should not be null-terminated. + * + * If linelen contains non-hex characters, return -1. Otherwise, return the + * numeric value of the length header. + */ +int packet_length(const char linelen[4]); + /* * Read a packetized line into a buffer like the 'packet_read()' function but * returns an 'enum packet_read_status' which indicates the status of the read. From patchwork Mon May 18 15:47:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 183C91391 for ; Mon, 18 May 2020 15:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF63F20657 for ; Mon, 18 May 2020 15:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J/oh6kQs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728361AbgERPro (ORCPT ); Mon, 18 May 2020 11:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgERPrm (ORCPT ); Mon, 18 May 2020 11:47:42 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E89C061A0C for ; Mon, 18 May 2020 08:47:41 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id dh1so1046438qvb.13 for ; Mon, 18 May 2020 08:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MGrW45YWMf7gQ4hYteUreyzMdi7RXw7Plla6a/9qun0=; b=J/oh6kQsVRyrqx6oDb9xl8kZtCSPLdwL5/Vn/C/UeMYcIfqQEfz5LtkJNLUt2ApTMN RVy5vs8tRpHDpnn6wRCudlgxBDp6WKHgGtjVF261lv1JaNN15Kzyojo5ixOIggRHnAiq ElbHAOMK/cd4AEGapQWZlAuVTOqKVXj/JWGrqgvqP4e62LBdZmH6I1TQyc1I/ZDogXgf elXSx35Ym9YUPglW3cnhFMtiYYExJIvD9777AQ7hYCCUMlUTHZZmciBAP765Jl0VcPzO fGhDQ6JANeVZfjMET7juX039N448fFTXOIilM9m23NBboPfX1doAGL3jrwLgipFObj3d /5rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MGrW45YWMf7gQ4hYteUreyzMdi7RXw7Plla6a/9qun0=; b=FggWgt55oq/c6NIF7G1sHL8Vj22zRTfDr9/73cZ7ye7F+PhzbN8LGuGlvSlYCe56Bc K1bAjlFY9hJ+nqut1pvffaFh9SZqPb5hNUEU9chynbBuJNsol0HTiTQ5WSi8ZXwH8Vud GT0O4EJEoX/b/MO+DnZrYV40wPHghSlwheFPUe72SaLxiBf8y5N2gK4h5vbvibvSVFue sY8J20TEk3HOOJNJQQ4GAovXf/I26Hczm4yEhfHA/y3ybZdYJd+c5iNoPfd9S85wvOF/ P49jRPJq4zP4tN/xgOE/W9HwItqWBsc+m7REvY7VuwUDsgluSeQzK3R08sEBZ26jRiGK gwcQ== X-Gm-Message-State: AOAM532RWqNcBwfee3VpFK4gkDVpE6cSdvxhP9z1QwAzLe63maWp+wAP DPjKnXusQe8H98QiYDxv8fc8BKxW X-Google-Smtp-Source: ABdhPJwdhRc6eNH8gOFF4xZayD6xSxIScQKI7cU8n8sHFMou9WlbvfdwrDjjjDJZUoBaNE5DOr0OSQ== X-Received: by 2002:a0c:fc45:: with SMTP id w5mr16445039qvp.75.1589816860510; Mon, 18 May 2020 08:47:40 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:39 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 5/7] remote-curl: error on incomplete packet Date: Mon, 18 May 2020 11:47:22 -0400 Message-Id: <52ce5fdffd6741eeee8d69b804403383da0d879d.1589816719.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently, remote-curl acts as a proxy and blindly forwards packets between an HTTP server and fetch-pack. In the case of a stateless RPC connection where the connection is terminated with a partially written packet, remote-curl will blindly send the partially written packet before waiting on more input from fetch-pack. Meanwhile, fetch-pack will read the partial packet and continue reading, expecting more input. This results in a deadlock between the two processes. For a stateless connection, inspect packets before sending them and error out if a a packet line packet is incomplete. Helped-by: Jeff King Signed-off-by: Denton Liu --- remote-curl.c | 59 ++++++++++++++++++- t/lib-httpd.sh | 2 + t/lib-httpd/apache.conf | 8 +++ .../incomplete-body-upload-pack-v2-http.sh | 3 + .../incomplete-length-upload-pack-v2-http.sh | 3 + t/t5702-protocol-v2.sh | 34 +++++++++++ 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 t/lib-httpd/incomplete-body-upload-pack-v2-http.sh create mode 100644 t/lib-httpd/incomplete-length-upload-pack-v2-http.sh diff --git a/remote-curl.c b/remote-curl.c index da3e07184a..e020140092 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -679,9 +679,53 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp) } #endif +struct check_pktline_state { + char len_buf[4]; + int len_filled; + int remaining; +}; + +static void check_pktline(struct check_pktline_state *state, const char *ptr, size_t size) +{ + while (size) { + if (!state->remaining) { + int digits_remaining = 4 - state->len_filled; + if (digits_remaining > size) + digits_remaining = size; + memcpy(&state->len_buf[state->len_filled], ptr, digits_remaining); + state->len_filled += digits_remaining; + ptr += digits_remaining; + size -= digits_remaining; + + if (state->len_filled == 4) { + state->remaining = packet_length(state->len_buf); + if (state->remaining < 0) { + die(_("remote-curl: bad line length character: %.4s"), state->len_buf); + } else if (state->remaining < 4) { + state->remaining = 0; + } else { + state->remaining -= 4; + } + state->len_filled = 0; + } + } + + if (state->remaining) { + int remaining = state->remaining; + if (remaining > size) + remaining = size; + ptr += remaining; + size -= remaining; + state->remaining -= remaining; + } + } +} + struct rpc_in_data { struct rpc_state *rpc; struct active_request_slot *slot; + int check_pktline; + struct check_pktline_state pktline_state; }; /* @@ -702,6 +746,8 @@ static size_t rpc_in(char *ptr, size_t eltsize, return size; if (size) data->rpc->any_written = 1; + if (data->check_pktline) + check_pktline(&data->pktline_state, ptr, size); write_or_die(data->rpc->in, ptr, size); return size; } @@ -778,7 +824,7 @@ static curl_off_t xcurl_off_t(size_t len) * If flush_received is true, do not attempt to read any more; just use what's * in rpc->buf. */ -static int post_rpc(struct rpc_state *rpc, int flush_received) +static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_received) { struct active_request_slot *slot; struct curl_slist *headers = http_copy_default_headers(); @@ -920,6 +966,8 @@ static int post_rpc(struct rpc_state *rpc, int flush_received) curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in); rpc_in_data.rpc = rpc; rpc_in_data.slot = slot; + rpc_in_data.check_pktline = stateless_connect; + memset(&rpc_in_data.pktline_state, 0, sizeof(rpc_in_data.pktline_state)); curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data); curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0); @@ -936,6 +984,11 @@ static int post_rpc(struct rpc_state *rpc, int flush_received) if (!rpc->any_written) err = -1; + if (rpc_in_data.pktline_state.len_filled) + err = error(_("%d bytes of length header were received"), rpc_in_data.pktline_state.len_filled); + if (rpc_in_data.pktline_state.remaining) + err = error(_("%d bytes of body are still expected"), rpc_in_data.pktline_state.remaining); + curl_slist_free_all(headers); free(gzip_body); return err; @@ -985,7 +1038,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads, break; rpc->pos = 0; rpc->len = n; - err |= post_rpc(rpc, 0); + err |= post_rpc(rpc, 0, 0); } close(client.in); @@ -1342,7 +1395,7 @@ static int stateless_connect(const char *service_name) BUG("The entire rpc->buf should be larger than LARGE_PACKET_MAX"); if (status == PACKET_READ_EOF) break; - if (post_rpc(&rpc, status == PACKET_READ_FLUSH)) + if (post_rpc(&rpc, 1, status == PACKET_READ_FLUSH)) /* We would have an err here */ break; /* Reset the buffer for next request */ diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 1449ee95e9..d2edfa4c50 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -129,6 +129,8 @@ install_script () { prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" + install_script incomplete-length-upload-pack-v2-http.sh + install_script incomplete-body-upload-pack-v2-http.sh install_script broken-smart-http.sh install_script error-smart-http.sh install_script error.sh diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 994e5290d6..afa91e38b0 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -117,6 +117,8 @@ Alias /auth/dumb/ www/auth/dumb/ SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} SetEnv GIT_HTTP_EXPORT_ALL +ScriptAlias /smart/incomplete_length/git-upload-pack incomplete-length-upload-pack-v2-http.sh/ +ScriptAlias /smart/incomplete_body/git-upload-pack incomplete-body-upload-pack-v2-http.sh/ ScriptAliasMatch /error_git_upload_pack/(.*)/git-upload-pack error.sh/ ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ @@ -126,6 +128,12 @@ ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1 Options FollowSymlinks + + Options ExecCGI + + + Options ExecCGI + Options ExecCGI diff --git a/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh b/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh new file mode 100644 index 0000000000..2f5ed9fcf6 --- /dev/null +++ b/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh @@ -0,0 +1,3 @@ +printf "Content-Type: text/%s\n" "application/x-git-upload-pack-result" +echo +printf "%s%s\n" "0079" "45" diff --git a/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh b/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh new file mode 100644 index 0000000000..86c6e648c9 --- /dev/null +++ b/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh @@ -0,0 +1,3 @@ +printf "Content-Type: text/%s\n" "application/x-git-upload-pack-result" +echo +printf "%s\n" "00" diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 5039e66dc4..4eb81ba2d4 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -586,6 +586,40 @@ test_expect_success 'clone with http:// using protocol v2' ' ! grep "Send header: Transfer-Encoding: chunked" log ' +test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' ' + test_when_finished "rm -f log" && + + git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" && + test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ + clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log && + # Client reported appropriate failure + test_i18ngrep "bytes of length header were received" err +' + +test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' ' + test_when_finished "rm -f log" && + + git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" && + test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ + clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log && + # Client reported appropriate failure + test_i18ngrep "bytes of body are still expected" err +' + test_expect_success 'clone big repository with http:// using protocol v2' ' test_when_finished "rm -f log" && From patchwork Mon May 18 15:47:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CE66913 for ; Mon, 18 May 2020 15:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB04220758 for ; Mon, 18 May 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UCqj+g39" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728368AbgERPro (ORCPT ); Mon, 18 May 2020 11:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728351AbgERPrm (ORCPT ); Mon, 18 May 2020 11:47:42 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9DDAC05BD09 for ; Mon, 18 May 2020 08:47:42 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id m11so10567258qka.4 for ; Mon, 18 May 2020 08:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T9Umo+uQnskgYD0VKJjB6NmZc/j0wcFhDiAeS4u5wxE=; b=UCqj+g39NYE8RGNuU7/H6dMLS5hBN+v7uSUInm+nrpBs5DcWsdRvD8z2qcjCiT0Q/7 IBr75PB9x2Yt3S10xnpn+/t3PgTRiE753jjXXt3e9J6PEMdBvSTIIXCzrR8+mNnhoNEX HCQ0gUu0ufMsNr+E4ClcW4kzDPZiTLk+HNQbiADddQuKrfeclBb4wNHvOBnw9Ovv0OR3 SB+bFfUyr7d1x0JclN51Lm7eGnw+DkIQ9GOQ0Uk0tv5W0jWRyUmvaFxNQn/RvWhSQ/W5 xXSNhu7GLnYcNiT2n4fWL0UakWUjRhI1bSC95+Hx6vzpY26NihrbDWrnB2OIxOsR2wpE R6lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T9Umo+uQnskgYD0VKJjB6NmZc/j0wcFhDiAeS4u5wxE=; b=A8y5y9qPkmo4tVwq91ZobQNIwNMyVHe2UP5S62lPUPBc/tTufGH+C58JtGr925R3IW CfmPGmkOOpG5K+2yNqWj2uJmPpLsr9xsvFlfkmuAzLWD+a0OyEMi5pZT9cqyPhcrdJ6l jsoTIQTE92HV/8awCVmGyMoZtwTRTA1io4uLoujkjnuFhZ3U1hC8N172Da6BBW7QDZs5 AAICGU3zICyx0waQUZG8877HsSRBWgpLtr+tsZh6J0j078VWViqriAjsFdOZRS886Q8A 6stlFkvb4PmwjMzFjSuNTnjlpOS2WQbMbdlG884M6S/x7xtkYcFd3OodDFYZar+Jf9R/ TQ8w== X-Gm-Message-State: AOAM531gMuD90ZCGtD8TIV19baJ2rXyptEonKFj96tDaEbo5zTMw7dza fCYUWf5pi14ck2MgqNCS9ZPhm8wR X-Google-Smtp-Source: ABdhPJwNfec51qXl2z7yxSED6SgAujfTEq2Z/Wn3g2bNdSlMazXrNzvOLe3V1QUiD3Nt/NmS7AJr1w== X-Received: by 2002:a37:f517:: with SMTP id l23mr16784967qkk.475.1589816861664; Mon, 18 May 2020 08:47:41 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine Subject: [PATCH v2 6/7] pkt-line: PACKET_READ_RESPONSE_END Date: Mon, 18 May 2020 11:47:23 -0400 Message-Id: <744b0783248efe1b43f80b9be21be6d380a11a08.1589816719.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will use PACKET_READ_RESPONSE_END to separate messages proxied by remote-curl. To prepare for this, add the PACKET_READ_RESPONSE_END enum value. In switch statements that need a case added, die() or BUG() when a PACKET_READ_RESPONSE_END is unexpected. Otherwise, mirror how PACKET_READ_DELIM is implemented (especially in cases where packets are being forwarded). Signed-off-by: Denton Liu --- connect.c | 2 ++ pkt-line.c | 11 +++++++++++ pkt-line.h | 2 ++ remote-curl.c | 2 ++ serve.c | 2 ++ t/helper/test-pkt-line.c | 4 ++++ 6 files changed, 23 insertions(+) diff --git a/connect.c b/connect.c index 23013c6344..11c6ec70a0 100644 --- a/connect.c +++ b/connect.c @@ -127,6 +127,7 @@ enum protocol_version discover_version(struct packet_reader *reader) die_initial_contact(0); case PACKET_READ_FLUSH: case PACKET_READ_DELIM: + case PACKET_READ_RESPONSE_END: version = protocol_v0; break; case PACKET_READ_NORMAL: @@ -310,6 +311,7 @@ struct ref **get_remote_heads(struct packet_reader *reader, state = EXPECTING_DONE; break; case PACKET_READ_DELIM: + case PACKET_READ_RESPONSE_END: die(_("invalid packet")); } diff --git a/pkt-line.c b/pkt-line.c index 5c3b4539b5..fdd6b90e68 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -99,6 +99,13 @@ void packet_delim(int fd) die_errno(_("unable to write delim packet")); } +void packet_response_end(int fd) +{ + packet_trace("0002", 4, 1); + if (write_in_full(fd, "0002", 4) < 0) + die_errno(_("unable to write stateless separator packet")); +} + int packet_flush_gently(int fd) { packet_trace("0000", 4, 1); @@ -337,6 +344,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer, packet_trace("0001", 4, 0); *pktlen = 0; return PACKET_READ_DELIM; + } else if (len == 2) { + packet_trace("0002", 4, 0); + *pktlen = 0; + return PACKET_READ_RESPONSE_END; } else if (len < 4) { die(_("protocol error: bad line length %d"), len); } diff --git a/pkt-line.h b/pkt-line.h index de81776a7a..8156445873 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -22,6 +22,7 @@ */ void packet_flush(int fd); void packet_delim(int fd); +void packet_response_end(int fd); void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3))); void packet_buf_flush(struct strbuf *buf); void packet_buf_delim(struct strbuf *buf); @@ -94,6 +95,7 @@ enum packet_read_status { PACKET_READ_NORMAL, PACKET_READ_FLUSH, PACKET_READ_DELIM, + PACKET_READ_RESPONSE_END, }; enum packet_read_status packet_read_with_status(int fd, char **src_buffer, size_t *src_len, char *buffer, diff --git a/remote-curl.c b/remote-curl.c index e020140092..d02cb547e9 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -601,6 +601,8 @@ static int rpc_read_from_out(struct rpc_state *rpc, int options, case PACKET_READ_FLUSH: memcpy(buf - 4, "0000", 4); break; + case PACKET_READ_RESPONSE_END: + die(_("remote server sent stateless separator")); } } diff --git a/serve.c b/serve.c index 317256c1a4..c046926ba1 100644 --- a/serve.c +++ b/serve.c @@ -217,6 +217,8 @@ static int process_request(void) state = PROCESS_REQUEST_DONE; break; + case PACKET_READ_RESPONSE_END: + BUG("unexpected stateless separator packet"); } } diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index 12ca698e17..69152958e5 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -46,6 +46,9 @@ static void unpack(void) case PACKET_READ_DELIM: printf("0001\n"); break; + case PACKET_READ_RESPONSE_END: + printf("0002\n"); + break; } } } @@ -75,6 +78,7 @@ static void unpack_sideband(void) case PACKET_READ_FLUSH: return; case PACKET_READ_DELIM: + case PACKET_READ_RESPONSE_END: break; } } From patchwork Mon May 18 15:47:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11555595 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07E0B913 for ; Mon, 18 May 2020 15:47:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D83B320758 for ; Mon, 18 May 2020 15:47:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nrJPER+Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728370AbgERPrp (ORCPT ); Mon, 18 May 2020 11:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728362AbgERPro (ORCPT ); Mon, 18 May 2020 11:47:44 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1980BC061A0C for ; Mon, 18 May 2020 08:47:44 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id dh1so1046515qvb.13 for ; Mon, 18 May 2020 08:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EsqxVE19hlxPM+IuRUzPbFuzwchKeAyRF0C1KT7Dj+w=; b=nrJPER+QfOt4kOSRglYWnwcqom1RwoMjdtJRkDDFj80BHtN9SuaVH915tRdquw+UjY bSCs+pQN/mR6Gspun0rMKc4w9j2KazemOQ41kSx8JqqVPqG7YTlYqdJlxmo8jnaSLFz6 DxhRUtJr1bGr4y5HXvZYh6MMFeMS/CieoxqluYxmAXOO367D9n+FPoEWh5f/TzIwSalM 0CYZHxtFI/Z5N4SG5TMg/+Gok9D1Acf6rOG48mg7c7Sng86f5etKfMscpHy+P2LKWr4K SIoOY8Kf7O7Rs1oFLHbCCfAeRz3YQqomhMosHy/HrUkPpJDezxPlTw6whNIe8Y+ZGxNL 1pbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EsqxVE19hlxPM+IuRUzPbFuzwchKeAyRF0C1KT7Dj+w=; b=OGabcWaJFA0qnvwipeItAutCn4xI4R9J/iP72mh09CNo7zLHc1A9oCionPtfb6R/Kk A4Fv/tLjmb/ixDq7ND7uhwmFZcFZGVbELiebig7rlcUcUjLjnzSJdk5nIUisNBXMvLPV eWaapX26BZEn0fiUDBsMGh6b52BuMenVXPHYjKMTzZUcVE+uidzrI63V30/3PMLqDZWx 7qH4eAMTKOVoV/r1bPCfD0pcEe+beKC+cer67olutU6hNTgGeqYLABN1tIuM+vFv8okn 0yBFjSn1KuVmwc0lpj4AjeTbmLDD5tZ75v8i0WcZNEWETCs6ksxmvODCNnLwvdnOGgRP epsA== X-Gm-Message-State: AOAM532pilHvZ8mQ4YbOyFkn88VPAUDAHRHruliC7wv4ZDlcjHLFTBW6 b2dV8tbSk5wXq3NZqNT6YpfrVYJy X-Google-Smtp-Source: ABdhPJz1kUNCggNE8dHZkH9qAAhkCLIpxV+C2qhWqOCd5G98hkM+1TTlyfJzc9J6E4pY3YoUsH7Hog== X-Received: by 2002:a05:6214:1543:: with SMTP id t3mr17158571qvw.122.1589816862816; Mon, 18 May 2020 08:47:42 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id z201sm5146913qkb.2.2020.05.18.08.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:47:42 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jeff King , Eric Sunshine , Force Charlie Subject: [PATCH v2 7/7] stateless-connect: send response end packet Date: Mon, 18 May 2020 11:47:24 -0400 Message-Id: <4b079bcd83ea80b8a0e81b0c1e3d5e083efeb9c6.1589816719.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.2.706.g87896c9627 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently, remote-curl acts as a proxy and blindly forwards packets between an HTTP server and fetch-pack. In the case of a stateless RPC connection where the connection is terminated before the transaction is complete, remote-curl will blindly forward the packets before waiting on more input from fetch-pack. Meanwhile, fetch-pack will read the transaction and continue reading, expecting more input to continue the transaction. This results in a deadlock between the two processes. This can be seen in the following command which does not terminate: $ git -c protocol.version=2 clone https://github.com/git/git.git --shallow-since=20151012 Cloning into 'git'... whereas the v1 version does terminate as expected: $ git -c protocol.version=1 clone https://github.com/git/git.git --shallow-since=20151012 Cloning into 'git'... fatal: the remote end hung up unexpectedly Instead of blindly forwarding packets, make remote-curl insert response end and flush packets after proxying the responses from the remote server when using stateless_connect(). On the RPC client side, ensure that each response ends as described. A separate control packet is chosen because we need to be able to differentiate between what the remote server sends and remote-curl's control packets. By ensuring in the remote-curl code that a server cannot send response end packets, we prevent a malicious server from being able to perform a denial of service attack in which they spoof a response end packet and cause the described deadlock to happen. Reported-by: Force Charlie Helped-by: Jeff King Signed-off-by: Denton Liu --- Documentation/gitremote-helpers.txt | 4 +++- Documentation/technical/protocol-v2.txt | 2 ++ builtin/fetch-pack.c | 2 +- connect.c | 10 +++++++++- fetch-pack.c | 12 ++++++++++++ remote-curl.c | 7 +++++++ remote.h | 3 ++- t/t5702-protocol-v2.sh | 13 +++++++++++++ transport.c | 3 ++- 9 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Documentation/gitremote-helpers.txt b/Documentation/gitremote-helpers.txt index f48a031dc3..84f8e92b23 100644 --- a/Documentation/gitremote-helpers.txt +++ b/Documentation/gitremote-helpers.txt @@ -405,7 +405,9 @@ Supported if the helper has the "connect" capability. trying to fall back). After line feed terminating the positive (empty) response, the output of the service starts. Messages (both request and response) must consist of zero or more - PKT-LINEs, terminating in a flush packet. The client must not + PKT-LINEs, terminating in a flush packet. Response messages will + have a response end packet before the flush packet to indicate + the end of a response. The client must not expect the server to store any state in between request-response pairs. After the connection ends, the remote helper exits. + diff --git a/Documentation/technical/protocol-v2.txt b/Documentation/technical/protocol-v2.txt index 7e3766cafb..3996d70891 100644 --- a/Documentation/technical/protocol-v2.txt +++ b/Documentation/technical/protocol-v2.txt @@ -33,6 +33,8 @@ In protocol v2 these special packets will have the following semantics: * '0000' Flush Packet (flush-pkt) - indicates the end of a message * '0001' Delimiter Packet (delim-pkt) - separates sections of a message + * '0002' Message Packet (response-end-pkt) - indicates the end of a response + for stateless connections Initial Client Request ---------------------- diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 4771100072..94b0c89b82 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -224,7 +224,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) version = discover_version(&reader); switch (version) { case protocol_v2: - get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL); + get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL, args.stateless_rpc); break; case protocol_v1: case protocol_v0: diff --git a/connect.c b/connect.c index 11c6ec70a0..12b57f5c0a 100644 --- a/connect.c +++ b/connect.c @@ -409,7 +409,8 @@ static int process_ref_v2(const char *line, struct ref ***list) struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **list, int for_push, const struct argv_array *ref_prefixes, - const struct string_list *server_options) + const struct string_list *server_options, + int stateless_rpc) { int i; *list = NULL; @@ -446,6 +447,13 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, if (reader->status != PACKET_READ_FLUSH) die(_("expected flush after ref listing")); + if (stateless_rpc) { + if (packet_reader_read(reader) != PACKET_READ_RESPONSE_END) + die(_("expected response end packet after ref listing")); + if (packet_reader_read(reader) != PACKET_READ_FLUSH) + die(_("expected flush packet after response end")); + } + return list; } diff --git a/fetch-pack.c b/fetch-pack.c index f73a2ce6cb..bcbbb7e2fb 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1468,6 +1468,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, struct fetch_negotiator negotiator_alloc; struct fetch_negotiator *negotiator; int seen_ack = 0; + int check_http_delimiter; if (args->no_dependents) { negotiator = NULL; @@ -1486,6 +1487,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, } while (state != FETCH_DONE) { + check_http_delimiter = 0; + switch (state) { case FETCH_CHECK_LOCAL: sort_ref_list(&ref, ref_compare_name); @@ -1542,6 +1545,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, /* fallthrough */ case NO_COMMON_FOUND: state = FETCH_SEND_REQUEST; + check_http_delimiter = 1; break; } break; @@ -1562,10 +1566,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, die(_("git fetch-pack: fetch failed.")); state = FETCH_DONE; + check_http_delimiter = 1; break; case FETCH_DONE: continue; } + + if (args->stateless_rpc && check_http_delimiter) { + if (packet_reader_read(&reader) != PACKET_READ_RESPONSE_END) + die(_("git fetch-pack: expected response end packet")); + if (packet_reader_read(&reader) != PACKET_READ_FLUSH) + die(_("git fetch-pack: expected flush packet")); + } } if (negotiator) diff --git a/remote-curl.c b/remote-curl.c index d02cb547e9..8a72b5ee7a 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -703,6 +703,8 @@ static void check_pktline(struct check_pktline_state *state, const char *ptr, si state->remaining = packet_length(state->len_buf); if (state->remaining < 0) { die(_("remote-curl: bad line length character: %.4s"), state->len_buf); + } else if (state->remaining == 2) { + die(_("remote-curl: unexpected response end packet")); } else if (state->remaining < 4) { state->remaining = 0; } else { @@ -991,6 +993,11 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece if (rpc_in_data.pktline_state.remaining) err = error(_("%d bytes of body are still expected"), rpc_in_data.pktline_state.remaining); + if (stateless_connect) { + packet_response_end(rpc->in); + packet_flush(rpc->in); + } + curl_slist_free_all(headers); free(gzip_body); return err; diff --git a/remote.h b/remote.h index 11d8719b58..5cc26c1b3b 100644 --- a/remote.h +++ b/remote.h @@ -179,7 +179,8 @@ struct ref **get_remote_heads(struct packet_reader *reader, struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **list, int for_push, const struct argv_array *ref_prefixes, - const struct string_list *server_options); + const struct string_list *server_options, + int stateless_rpc); int resolve_remote_symref(struct ref *ref, struct ref *list); diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 4eb81ba2d4..8da65e60de 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -620,6 +620,19 @@ test_expect_success 'clone repository with http:// using protocol v2 with incomp test_i18ngrep "bytes of body are still expected" err ' +test_expect_success 'clone with http:// using protocol v2 and invalid parameters' ' + test_when_finished "rm -f log" && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \ + git -c protocol.version=2 \ + clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log +' + test_expect_success 'clone big repository with http:// using protocol v2' ' test_when_finished "rm -f log" && diff --git a/transport.c b/transport.c index a6002e502f..182978f4be 100644 --- a/transport.c +++ b/transport.c @@ -297,7 +297,8 @@ static struct ref *handshake(struct transport *transport, int for_push, if (must_list_refs) get_remote_refs(data->fd[1], &reader, &refs, for_push, ref_prefixes, - transport->server_options); + transport->server_options, + transport->stateless_rpc); break; case protocol_v1: case protocol_v0: