From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alexey Abramov via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#51133: [PATCH 1/1] Tolerate http response line without reason phrase Date: Tue, 12 Oct 2021 16:35:29 +0200 Message-ID: <87lf2yjopa.fsf@delta.lan> References: <20211011070355.20408-1-levenson@mmer.org> <87h7dmhdts.fsf@riseup.net> <875yu2r6mp.fsf@delta.lan> <87bl3uh86a.fsf@riseup.net> Reply-To: Alexey Abramov Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6181"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 51133@debbugs.gnu.org To: jakub-w@riseup.net Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Tue Oct 12 16:36:12 2021 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maIt0-0001KQ-F5 for guile-bugs@m.gmane-mx.org; Tue, 12 Oct 2021 16:36:10 +0200 Original-Received: from localhost ([::1]:37802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1maIsz-0002xk-5G for guile-bugs@m.gmane-mx.org; Tue, 12 Oct 2021 10:36:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maIst-0002uO-BP for bug-guile@gnu.org; Tue, 12 Oct 2021 10:36:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34085) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maIst-0005dG-2M for bug-guile@gnu.org; Tue, 12 Oct 2021 10:36:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1maIss-0003Gs-Vt for bug-guile@gnu.org; Tue, 12 Oct 2021 10:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alexey Abramov Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 12 Oct 2021 14:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51133 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: bug-guile@gnu.org, 51133@debbugs.gnu.org Original-Received: via spool by 51133-submit@debbugs.gnu.org id=B51133.163404936212563 (code B ref 51133); Tue, 12 Oct 2021 14:36:02 +0000 Original-Received: (at 51133) by debbugs.gnu.org; 12 Oct 2021 14:36:02 +0000 Original-Received: from localhost ([127.0.0.1]:45628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maIsr-0003GA-5j for submit@debbugs.gnu.org; Tue, 12 Oct 2021 10:36:02 -0400 Original-Received: from mail.mmer.org ([178.22.65.174]:51964) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1maIso-0003FZ-5z for 51133@debbugs.gnu.org; Tue, 12 Oct 2021 10:35:59 -0400 Original-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= Original-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) In-Reply-To: <87bl3uh86a.fsf@riseup.net> (jakub-w@riseup.net's message of "Tue, 12 Oct 2021 12:03:09 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10192 Archived-At: --=-=-= 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 --=-=-=--