guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 14/23: refactoring to (web server ethreads) read-http-li


From: Andy Wingo
Subject: [Guile-commits] 14/23: refactoring to (web server ethreads) read-http-line
Date: Thu, 24 Mar 2016 14:26:04 +0000

wingo pushed a commit to branch wip-ethreads
in repository guile.

commit b620f71c71a1016bbeb3e7ed125a88925fd3a27b
Author: Andy Wingo <address@hidden>
Date:   Tue Mar 27 00:14:52 2012 +0200

    refactoring to (web server ethreads) read-http-line
    
    * module/web/server/ethreads.scm (read-http-line): Use
      get-latin1-string-delimited with a limit on the line length.
---
 module/web/server/ethreads.scm |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/module/web/server/ethreads.scm b/module/web/server/ethreads.scm
index 17ae37c..9445e8a 100644
--- a/module/web/server/ethreads.scm
+++ b/module/web/server/ethreads.scm
@@ -75,20 +75,23 @@
   (throw 'bad-request msg args))
 
 (define (read-http-line eport)
-  ;; 10 and 13 are #\newline and #\return, respectively.
-  (define (end-of-line? u8)
-    (or (eqv? u8 10) (eqv? u8 13)))
-  (call-with-values (lambda ()
-                      (get-bytevector-delimited eport end-of-line?))
-    (lambda (bv delim)
+  (define (end-of-line? c)
+    (or (eqv? c #\newline) (eqv? c #\return)))
+  (call-with-values
+      (lambda ()
+        ;; Restrict to 512 chars to avoid denial of service attacks.
+        (get-latin1-string-delimited eport end-of-line? #:max-chars 512))
+    (lambda (str delim)
       (cond
+       ((not delim)
+        (bad-request "Line too long: ~S" str))
        ((eof-object? delim)
-        (bad-request "EOF while reading line: ~S" bv))
+        (bad-request "EOF while reading line: ~S" str))
        (else
-        (when (and (eqv? delim 13)
-                   (eqv? (lookahead-u8 eport) 10))
+        (when (and (eqv? delim #\return)
+                   (eqv? (lookahead-u8 eport) (char->integer #\newline)))
           (get-u8 eport))
-        (utf8->string bv))))))
+        str)))))
 
 (define (continuation-line? port)
   (let ((c (lookahead-u8 port)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]