From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 11 03:04:29 2021 Received: (at submit) by debbugs.gnu.org; 11 Oct 2021 07:04:29 +0000 Received: from localhost ([127.0.0.1]:56286 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZpMK-0003kF-SW for submit@debbugs.gnu.org; Mon, 11 Oct 2021 03:04:29 -0400 Received: from lists.gnu.org ([209.51.188.17]:35324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZpMH-0003k5-1a for submit@debbugs.gnu.org; Mon, 11 Oct 2021 03:04:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZpMF-00080h-R4 for bug-guile@gnu.org; Mon, 11 Oct 2021 03:04:24 -0400 Received: from mail.mmer.org ([178.22.65.174]:48654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZpME-00050Q-2x for bug-guile@gnu.org; Mon, 11 Oct 2021 03:04:23 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id 29d24c22 for ; Mon, 11 Oct 2021 07:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to :subject:date:message-id:mime-version:content-transfer-encoding; s=dkim; bh=g55cgYrk7ZeTKFn4b5yQrg7N3luRB9A6Tn9wpuS1zk4=; b=R+wP oUEA9svnMFg1U/lm2V8mPDp6LWrgO1TlPfw1p6XIhayHMnL58tFwHpxZSrGUZHl+ v6krf8hYtU7qNOR3bSzg/GiLxl3/HCNw63o7qHetwXWCJRF1TaKvlnla+8wqylMW cRgq8U09fwlPhPcIbAKi1jEPZy39/hYk0shpI70= Received: from delta (j74182.upc-j.chello.nl [24.132.74.182]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id 4d492ff5 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Mon, 11 Oct 2021 07:04:10 +0000 (UTC) From: Alexey Abramov To: bug-guile@gnu.org Subject: [PATCH 1/1] Tolerate http response line without reason phrase Date: Mon, 11 Oct 2021 09:03:55 +0200 Message-Id: <20211011070355.20408-1-levenson@mmer.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=178.22.65.174; envelope-from=levenson@mmer.org; helo=mail.mmer.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) * module/web/http.scm (read-response-line): Use the end of the string, in case a line doesn't have char-set:whitespace at the end. * test-suite/tests/web-http.test ("read-response-line"): Add test. --- module/web/http.scm | 6 ++++-- test-suite/tests/web-http.test | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/module/web/http.scm b/module/web/http.scm index 4276e1744..7443bd6a4 100644 --- a/module/web/http.scm +++ b/module/web/http.scm @@ -1187,8 +1187,10 @@ values: the HTTP version, the response code, and the (possibly empty) \"reason phrase\"." (let* ((line (read-header-line port)) (d0 (string-index line char-set:whitespace)) ; "delimiter zero" - (d1 (and d0 (string-index line char-set:whitespace - (skip-whitespace line d0))))) + (d1 (and d0 (or (string-index line char-set:whitespace + (skip-whitespace line d0)) + ;; tolerate responses with empty "reason phrase" + (string-length line))))) (unless (and d0 d1) (bad-response "Bad Response-Line: ~s" line)) (values (parse-http-version line 0 d0) diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test index 63377349c..6d8cd1642 100644 --- a/test-suite/tests/web-http.test +++ b/test-suite/tests/web-http.test @@ -216,6 +216,8 @@ ;; Empty reason phrases are valid; see . (pass-if-read-response-line "HTTP/1.1 302 " + (1 . 1) 302 "") + (pass-if-read-response-line "HTTP/1.1 302" (1 . 1) 302 "")) (with-test-prefix "write-response-line" -- 2.31.1 From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 12 04:02:15 2021 Received: (at submit) by debbugs.gnu.org; 12 Oct 2021 08:02:15 +0000 Received: from localhost ([127.0.0.1]:33381 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maCjm-0004WP-Ps for submit@debbugs.gnu.org; Tue, 12 Oct 2021 04:02:14 -0400 Received: from lists.gnu.org ([209.51.188.17]:40276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maCjk-0004WC-PM for submit@debbugs.gnu.org; Tue, 12 Oct 2021 04:02:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCjk-0007jL-Ex for bug-guile@gnu.org; Tue, 12 Oct 2021 04:02:12 -0400 Received: from mx1.riseup.net ([198.252.153.129]:41162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCji-0003ow-8e for bug-guile@gnu.org; Tue, 12 Oct 2021 04:02:11 -0400 Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4HT7Rf0TSxzF4qg; Tue, 12 Oct 2021 01:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1634025726; bh=s8zkjk0AO7eaMmPYhadGYLrdqJMODC8xoyhXPXP6eBI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=RomA2obR3YhPrjafylbNUwkfbTYpMMKMxihPbtzNCICnXv4YUPRKbHg6F16qK4YHc yKEoJ4yiiQjrjdRQzpqR38E3N2pj3YYLcz/83AQBZkjUc9v4wqSgCO3vG/bmNsfRpM UWtnlXYM58n99iDMfprxb7STVmMnLqxXf2+Y34Pw= X-Riseup-User-ID: 9009DAFA6C0F5E1A62075D39C4858D5F3751B8E658D2C49A0106135606A3D0B2 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4HT7Rc61T8z5wDQ; Tue, 12 Oct 2021 01:02:04 -0700 (PDT) From: jakub-w@riseup.net To: bug-guile@gnu.org Subject: Re: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase References: <20211011070355.20408-1-levenson@mmer.org> Date: Tue, 12 Oct 2021 10:01:03 +0200 In-Reply-To: <20211011070355.20408-1-levenson@mmer.org> (Alexey Abramov via's message of "Mon, 11 Oct 2021 09:03:55 +0200") Message-ID: <87h7dmhdts.fsf@riseup.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=198.252.153.129; envelope-from=jakub-w@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 51133@debbugs.gnu.org, Alexey Abramov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) I don't think the reason phrase is optional, even though it can be just a whitespace. Even if I'm not mistaken, however, I don't see the reason for Guile not to be able to parse the status line without a space at the end. Aside from that consider a string "HTTP/1.1 ", which should be a bad response because the status code should definitely be obligatory, however it passes through the (and d0 d1) check after applying this patch. From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 12 04:26:59 2021 Received: (at submit) by debbugs.gnu.org; 12 Oct 2021 08:26:59 +0000 Received: from localhost ([127.0.0.1]:33447 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maD7j-0007Ko-2J for submit@debbugs.gnu.org; Tue, 12 Oct 2021 04:26:59 -0400 Received: from lists.gnu.org ([209.51.188.17]:33944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maD7h-0007Kf-GX for submit@debbugs.gnu.org; Tue, 12 Oct 2021 04:26:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maD7h-0006cM-1x for bug-guile@gnu.org; Tue, 12 Oct 2021 04:26:57 -0400 Received: from mail.mmer.org ([178.22.65.174]:48656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maD7f-0002IG-0I for bug-guile@gnu.org; Tue, 12 Oct 2021 04:26:56 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id 0df0b4c9; Tue, 12 Oct 2021 08:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=dkim; bh=dCS+DbC+T5ajNgl//e+T4CcF7pe4vKdHKFyU4b bKJWs=; b=McGm5sSzpAclcwkWlCPwIi3cGWqGKBYQLaFBUmRqIT/ATQi9g+LKI6 a+vP4kVqxB3pJ10A70QKeO+J9EcYhhWhNYUd3oI1fU6G+DjUeoXBrEAB95XT59PL DdpKoD7j7BxM5qjdvpPG0ffxhu4sPOdV0KoIcMlmRZ8AoSpDrVd48= Received: from delta.lan (j74182.upc-j.chello.nl [24.132.74.182]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id 42a4b399 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 12 Oct 2021 08:26:44 +0000 (UTC) From: Alexey Abramov To: jakub-w@riseup.net Subject: Re: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase References: <20211011070355.20408-1-levenson@mmer.org> <87h7dmhdts.fsf@riseup.net> Date: Tue, 12 Oct 2021 10:26:22 +0200 In-Reply-To: <87h7dmhdts.fsf@riseup.net> (jakub-w@riseup.net's message of "Tue, 12 Oct 2021 10:01:03 +0200") Message-ID: <875yu2r6mp.fsf@delta.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=178.22.65.174; envelope-from=levenson@mmer.org; helo=mail.mmer.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: bug-guile@gnu.org, 51133@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Hi, I agree that it is not a complient http response, but unfortunately I came across with some http services (redfish, cimc from Cisco ), where they don't put a reason phrase. As you can see the difference is that response line doesn't have a space after the response code, that is why it raise an exception even though the documentation says 'and the (possibly empty) "reason phrase"'. I would call it as a follow up to f53145d41. -- Alexey From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 12 05:11:53 2021 Received: (at submit) by debbugs.gnu.org; 12 Oct 2021 09:11:53 +0000 Received: from localhost ([127.0.0.1]:33502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maDpA-0008SU-Vh for submit@debbugs.gnu.org; Tue, 12 Oct 2021 05:11:53 -0400 Received: from lists.gnu.org ([209.51.188.17]:51424) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maDp9-0008SM-CH for submit@debbugs.gnu.org; Tue, 12 Oct 2021 05:11:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maDp7-0005DP-LT for bug-guile@gnu.org; Tue, 12 Oct 2021 05:11:51 -0400 Received: from mail.tuxteam.de ([5.199.139.25]:40788) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1maDp5-0003Id-5m for bug-guile@gnu.org; Tue, 12 Oct 2021 05:11:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:Date; bh=Onv1Q0zhTYpQOtWNVOhexWbp8fXLNif0emJIzhVugL0=; b=Sc4tBiCYmizljGBUE9VwyHx4wsVUYZrJk1JwMz20cOeBExhW6hHUNlrKVwEyUJAh2lnNY/A2QuGQL0Mr/P9h1w/OGvXKuLANYARuakc3LQVhPaHdNTKUZXOBA22v7LCVRit29yBgDvgaJ4naLzUQuEQPxSufdKVcGtFZlt7t/dAF5XSVoEdg8s0OTeP68uTSDJqVhXFr5/ON0LDATjGUr4V3YOSNnF8f454DDz8UhMs99ysjC0A4Q0nzY2vvPVLZS4lQJM+37uFQA908Ctoe1B5lNxRyJROjuKe1pS3y8r2hHdIk3hR71wXrqBT3flpvRGtdZw5qr4mHplgBwDn8SQ==; Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1maDp1-0008TO-RX for bug-guile@gnu.org; Tue, 12 Oct 2021 11:11:43 +0200 Date: Tue, 12 Oct 2021 11:11:43 +0200 To: bug-guile@gnu.org Subject: Re: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase Message-ID: <20211012091143.GA32113@tuxteam.de> References: <20211011070355.20408-1-levenson@mmer.org> <87h7dmhdts.fsf@riseup.net> <875yu2r6mp.fsf@delta.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <875yu2r6mp.fsf@delta.lan> User-Agent: Mutt/1.5.21 (2010-09-15) From: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 12, 2021 at 10:26:22AM +0200, Alexey Abramov via Bug reports fo= r GUILE, GNU's Ubiquitous Extension Language wrote: > Hi, >=20 > I agree that it is not a complient http response, According to The Book [1] ;-) there should be at least one space (SP) (as far as I understand this is really a true honest space, Unicode codepoint 32. It is /not/ part of the message (aka "reason phrase") , but a separator. The rule is: status-line =3D HTTP-version SP status-code SP reason-phrase CRLF The reason phrase itself can contain whatever funny whitespace it wants: reason-phrase =3D *( HTAB / SP / VCHAR / obs-text ) and it /can/ be empty. That said I'd agree that it makes sense to tolerate a missing SP there. The legal minimum seems thus to be HTTP-version SP status-code SP CRLF > but unfortunately I > came across with some http services (redfish, cimc from Cisco ) uh-oh. All bets are off, then ;-) > where they don't put a reason phrase. That would be OK, but they also eat the mandatory separator space before the empty reason phrase. Bad folks, bad ;-) As an onlooker I haven't much to say, but I think you are right (but not Cisco :) Cheers - t --pf9I7BMVVzbSWLtt Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAmFlUU8ACgkQBcgs9XrR2kZTVwCfdaJSRXNKQdl7sIHRFbA/ep5p rcQAnjBje2OXpyjIyrOP6SAtfIkN9Lbo =RAnY -----END PGP SIGNATURE----- --pf9I7BMVVzbSWLtt-- From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 12 06:03:28 2021 Received: (at submit) by debbugs.gnu.org; 12 Oct 2021 10:03:28 +0000 Received: from localhost ([127.0.0.1]:33544 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maEd6-0001HU-FV for submit@debbugs.gnu.org; Tue, 12 Oct 2021 06:03:28 -0400 Received: from lists.gnu.org ([209.51.188.17]:38688) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maEd5-0001HN-G6 for submit@debbugs.gnu.org; Tue, 12 Oct 2021 06:03:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maEd4-0005F1-Jg for bug-guile@gnu.org; Tue, 12 Oct 2021 06:03:27 -0400 Received: from mx1.riseup.net ([198.252.153.129]:52348) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maEd2-0006Oi-Hg for bug-guile@gnu.org; Tue, 12 Oct 2021 06:03:25 -0400 Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4HTB7Z64QmzF4vk; Tue, 12 Oct 2021 03:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1634033002; bh=CSjSg7BV+Is05b5jeOJGrDWLRXZ9OX/KonCEvTXjGBw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=XaUfloEup0lty+9TN5RfT7+xcYlL9KPrGwdM/nXqri8/A3HDtCVHvgSJK7jrF2Lij dCrdCqig3016On6cafQsVVnHdlMHneKRsLP3t+XHvQgAzz+73QYdO4l/+QrP8cV5kQ kYRyqEySxQpg7okSzIBrRBamGAPYbzKa1M5Jx8m4= X-Riseup-User-ID: 481416EEB5ADAC0452E165B077E61829C5003A6F96B54A312A4FB577C5FEDBF6 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4HTB7Y4SHSz1yBS; Tue, 12 Oct 2021 03:03:21 -0700 (PDT) From: jakub-w@riseup.net To: bug-guile@gnu.org Subject: Re: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase References: <20211011070355.20408-1-levenson@mmer.org> <87h7dmhdts.fsf@riseup.net> <875yu2r6mp.fsf@delta.lan> Date: Tue, 12 Oct 2021 12:03:09 +0200 In-Reply-To: <875yu2r6mp.fsf@delta.lan> (Alexey Abramov via's message of "Tue, 12 Oct 2021 10:26:22 +0200") Message-ID: <87bl3uh86a.fsf@riseup.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=198.252.153.129; envelope-from=jakub-w@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 51133@debbugs.gnu.org, Alexey Abramov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) You're right but you didn't address my second point. The fact that with this patch (call-with-input-string "HTTP/1.1 \n" (lambda (port) (read-response-line port))) passes the check for 'bad-response error inside read-response-line. It throws 'bad-header-component from non-negative-integer instead because d1 is always true if d0 is true. From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 12 10:36:01 2021 Received: (at submit) by debbugs.gnu.org; 12 Oct 2021 14:36:01 +0000 Received: from localhost ([127.0.0.1]:45625 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maIsq-0003G6-KM for submit@debbugs.gnu.org; Tue, 12 Oct 2021 10:36:01 -0400 Received: from lists.gnu.org ([209.51.188.17]:41056) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maIsp-0003Fu-6E for submit@debbugs.gnu.org; Tue, 12 Oct 2021 10:35:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maIso-0002lx-VZ for bug-guile@gnu.org; Tue, 12 Oct 2021 10:35:58 -0400 Received: from mail.mmer.org ([178.22.65.174]:48658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maIsm-0005Xv-T2 for bug-guile@gnu.org; Tue, 12 Oct 2021 10:35:58 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id a867a99b; Tue, 12 Oct 2021 14:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=dkim; bh=eo3y8Ivfeu3/ompMsE4xLqo9lV1Yw9j53oWQuS DYED8=; b=8w9JW9daNoJleQh0e3LwOL8pxQjpzmn/gtweD4TWBqwAhb6se24SfJ I9piXa5pfvRbegNy1QpAfjP9Ozh274UYzubgVQsSTENWMat9ANRtDYyi1gXMuOyq +Yj9Ywm5pTdeIP43I1rkouM+8pWo6Yo1nhw4WVyBC+f3WD1KvvtBQ= Received: from delta.lan (j74182.upc-j.chello.nl [24.132.74.182]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id 70fbd699 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 12 Oct 2021 14:35:48 +0000 (UTC) From: Alexey Abramov To: jakub-w@riseup.net Subject: Re: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase References: <20211011070355.20408-1-levenson@mmer.org> <87h7dmhdts.fsf@riseup.net> <875yu2r6mp.fsf@delta.lan> <87bl3uh86a.fsf@riseup.net> Date: Tue, 12 Oct 2021 16:35:29 +0200 In-Reply-To: <87bl3uh86a.fsf@riseup.net> (jakub-w@riseup.net's message of "Tue, 12 Oct 2021 12:03:09 +0200") Message-ID: <87lf2yjopa.fsf@delta.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=178.22.65.174; envelope-from=levenson@mmer.org; helo=mail.mmer.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: bug-guile@gnu.org, 51133@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain jakub-w@riseup.net writes: > You're right but you didn't address my second point. > The fact that with this patch > > (call-with-input-string "HTTP/1.1 \n" > (lambda (port) (read-response-line port))) I see, my bad, thanks! Please find a newly attached patch. I added a test for such a case, but I am not sure about the indentation though. Please let me know what you think. -- Alexey --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-http-Tolerate-http-response-line-without-a-reason-ph.patch >From b589595db9ab448aa52d002c34d7919a601904e4 Mon Sep 17 00:00:00 2001 From: Alexey Abramov Date: Thu, 7 Oct 2021 13:45:02 +0200 Subject: [PATCH] http: Tolerate http response line without a reason phrase * module/web/http.scm (read-response-line): Use the end of the string, in case a line doesn't have char-set:whitespace at the end. * test-suite/tests/web-http.test ("read-response-line"): Add tests. * .dir-locals.el (scheme-mode): Add indentation rule for pass-if-named-exception. --- .dir-locals.el | 1 + module/web/http.scm | 20 +++++++++++++------- test-suite/tests/web-http.test | 8 +++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index 90257e7bf..e94ceb723 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -10,6 +10,7 @@ (eval . (put 'let/ec 'scheme-indent-function 1)) (eval . (put 'pass-if 'scheme-indent-function 1)) (eval . (put 'pass-if-exception 'scheme-indent-function 2)) + (eval . (put 'pass-if-named-exception 'scheme-indent-function 3)) (eval . (put 'pass-if-equal 'scheme-indent-function 2)) (eval . (put 'with-test-prefix 'scheme-indent-function 1)) (eval . (put 'with-test-prefix/c&e 'scheme-indent-function 1)) diff --git a/module/web/http.scm b/module/web/http.scm index 4276e1744..4053e5271 100644 --- a/module/web/http.scm +++ b/module/web/http.scm @@ -1187,14 +1187,20 @@ values: the HTTP version, the response code, and the (possibly empty) \"reason phrase\"." (let* ((line (read-header-line port)) (d0 (string-index line char-set:whitespace)) ; "delimiter zero" - (d1 (and d0 (string-index line char-set:whitespace - (skip-whitespace line d0))))) - (unless (and d0 d1) + (d1 (and d0 (or (string-index line char-set:whitespace + (skip-whitespace line d0)) + ;; tolerate responses with empty "reason phrase" + (string-length line))))) + (cond + ((not d0) + (bad-response "Bad Response-Line: ~s" line)) + ((and d0 d1 (string-null? (string-trim (substring line d0 d1)))) (bad-response "Bad Response-Line: ~s" line)) - (values (parse-http-version line 0 d0) - (parse-non-negative-integer line (skip-whitespace line d0 d1) - d1) - (string-trim-both line char-set:whitespace d1)))) + (else + (values (parse-http-version line 0 d0) + (parse-non-negative-integer line (skip-whitespace line d0 d1) + d1) + (string-trim-both line char-set:whitespace d1)))))) (define (write-response-line version code reason-phrase port) "Write the first line of an HTTP response to PORT." diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test index 63377349c..7d4885722 100644 --- a/test-suite/tests/web-http.test +++ b/test-suite/tests/web-http.test @@ -216,7 +216,13 @@ ;; Empty reason phrases are valid; see . (pass-if-read-response-line "HTTP/1.1 302 " - (1 . 1) 302 "")) + (1 . 1) 302 "") + (pass-if-read-response-line "HTTP/1.1 302" + (1 . 1) 302 "") + (pass-if-named-exception "missing HTTP code" bad-response "Bad Response-Line" + (call-with-input-string "HTTP/1.1 \n" + (lambda (port) + (read-response-line port))))) (with-test-prefix "write-response-line" (pass-if-write-response-line "HTTP/1.0 404 Not Found" -- 2.31.1 --=-=-=--