From patchwork Mon Sep 10 20:53:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kirillov X-Patchwork-Id: 10594785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A642A920 for ; Mon, 10 Sep 2018 20:54:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B0C293A0 for ; Mon, 10 Sep 2018 20:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89950293AD; Mon, 10 Sep 2018 20:54:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29BFA293A0 for ; Mon, 10 Sep 2018 20:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726862AbeIKBuK (ORCPT ); Mon, 10 Sep 2018 21:50:10 -0400 Received: from p3plsmtpa07-06.prod.phx3.secureserver.net ([173.201.192.235]:58425 "EHLO p3plsmtpa07-06.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbeIKBuK (ORCPT ); Mon, 10 Sep 2018 21:50:10 -0400 Received: from jessie.local ([212.149.203.197]) by :SMTPAUTH: with ESMTPSA id zTCEf4aLL0GwuzTCJfcmLH; Mon, 10 Sep 2018 13:54:16 -0700 From: Max Kirillov To: Jonathan Nieder Cc: git@vger.kernel.org, Jeff King , =?utf-8?q?Jelmer_Vernoo?= =?utf-8?q?=C4=B3?= , Florian Manschwetus , Max Kirillov Subject: [PATCH] http-backend: Treat empty CONTENT_LENGTH as zero Date: Mon, 10 Sep 2018 23:53:59 +0300 Message-Id: <20180910205359.32332-1-max@max630.net> X-Mailer: git-send-email 2.17.0.1185.g782057d875 In-reply-to: <20180910052558.GB55941@aiede.svl.corp.google.com> X-CMAE-Envelope: MS4wfDzyHMNe2FFkY8AYWU/kpAFcQBtjpZTFYOYtyAKjFEuncLzn+Dk976OZjkYVr2FOvsVK5hYYBK7u3SxxtRQnnEvu7hIk/+MvX6K3iqSBNnwTlRdoYela NjUoXC48+ywv7IjS2RnWVi6WjfGWr5LYyaCtvoVCTx37jXKr2DoTn403ARtEiIfNr7Zf2P4ffydI4zawbkQl05IN6FVsmNHIazE+AdO8D3Jey2lRibtZLxHJ k2coNGeiKAnRpHjQvNcZcvYtsjyVkrFg4EqSXEirHgk5iXl+weGQV42C9TGSxDXYxJjSkXa+e1dtEe1jf1bqnA== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff King Subject: [PATCH] http-backend: Treat empty CONTENT_LENGTH as zero There is no known case where empty body it used by a server as instruction to read until EOF, so there is no need to violate the RFC. Make get_content_length() return 0 in this case. Currently there is no practical difference, as the GET request where it can be empty is handled without actual reading the body (in get_info_refs() function), but it is better to stick to the correct behavior. Signed-off-by: Max Kirillov --- The incremental. Hopefully I described the reason right. Needs "signed-off-by" http-backend.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/http-backend.c b/http-backend.c index 458642ef72..ea36a52118 100644 --- a/http-backend.c +++ b/http-backend.c @@ -353,8 +353,28 @@ static ssize_t get_content_length(void) ssize_t val = -1; const char *str = getenv("CONTENT_LENGTH"); - if (str && *str && !git_parse_ssize_t(str, &val)) - die("failed to parse CONTENT_LENGTH: %s", str); + if (!str) { + /* + * RFC3875 says this must mean "no body", but in practice we + * receive chunked encodings with no CONTENT_LENGTH. Tell the + * caller to read until EOF. + */ + val = -1; + } else if (!*str) { + /* + * An empty length should be treated as "no body" according to + * RFC3875, and this seems to hold in practice. + */ + val = 0; + } else { + /* + * We have a non-empty CONTENT_LENGTH; trust what's in it as long + * as it can be parsed. + */ + if (!git_parse_ssize_t(str, &val)) + die("failed to parse CONTENT_LENGTH: '%s'", str); + } + return val; }