fukamachi / fast-http

A fast HTTP request/response parser for Common Lisp.
343 stars 37 forks source link

type error in collect-prev-header-value #30

Open slyrus opened 7 years ago

slyrus commented 7 years ago

So I'm trying to track down a memory corruption bug. First step is to turn off all of the speed/safety optimizations. When I do that I get a compilation error in make-parser's collect-prev-header-value flet:

...
    (flet ((collect-prev-header-value ()
             (when header-value-buffer
               (let ((header-value))
                 (if (string= parsing-header-field "set-cookie")
                     (push header-value (gethash "set-cookie" headers))
                     (multiple-value-bind (previous-value existp)
                         (gethash (the simple-string parsing-header-field) headers)
                       (setf (gethash (the simple-string parsing-header-field) headers)
                             (if existp
                                 (if (simple-string-p previous-value)
                                     (concatenate 'string (the simple-string previous-value) ", " header-value)
                                     (format nil "~A, ~A" previous-value header-value))
                                 (if (number-string-p header-value)
                                     (read-from-string header-value)
                                     header-value)))))))))

gives:

; 
; caught WARNING:
;   Derived type of HEADER-VALUE is
;     (VALUES NULL &OPTIONAL),
;   conflicting with its asserted type
;     SIMPLE-STRING.
;   See also:
;     The SBCL Manual, Node "Handling of Types"

the problem being that header-value is going to be nil when we call number-string-p on it. Probably not the bug I'm looking for, but a problem nonetheless.

slyrus commented 7 years ago

Not sure if this is helpful, but if I continue from the error, I get this backtrace:


Unhandled memory fault at #x0..
In #<COMPILED-TEMPLATE /root/quicklisp/dists/quicklisp/software/djula-20170227-git/templates/error-template.djhtml {2060B39B}>.
Date/time: 2017-06-02-04:37An unhandled error condition has been signalled:
Unhandled memory fault at #x0.

Backtrace for: #
0: (TRIVIAL-BACKTRACE:PRINT-BACKTRACE-TO-STREAM #)
1: (TRIVIAL-BACKTRACE:PRINT-BACKTRACE # :OUTPUT NIL :IF-EXISTS :APPEND :VERBOSE NIL)
2: #
3: ((LABELS MYWAY.MAPPER::DISPATCH-WITH-RULES :IN MYWAY.MAPPER:DISPATCH) (# # # # # # # # #))
4: ((:METHOD LACK.COMPONENT:CALL (NINGLE.APP: T)) # {1002290D63}> #) [fast-method]
5: ((:METHOD LACK.COMPONENT:CALL (CAVEMAN2.APP: T)) # {1002290D63}> (:LACK.SESSION.OPTIONS (:ID "0fc83f763b9b52531ac6923c277f91eb6759ee54" :NEW-SESSION T :CHANGE-ID NIL :EXPIRE NIL) :LACK.SESSION # :RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL)) [fast-method]
6: ((:METHOD LACK.COMPONENT:CALL :AROUND (NINGLE.APP: T)) # {1002290D63}> (:LACK.SESSION.OPTIONS (:ID "0fc83f763b9b52531ac6923c277f91eb6759ee54" :NEW-SESSION T :CHANGE-ID NIL :EXPIRE NIL) :LACK.SESSION # :RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL)) [fast-method]
7: ((LAMBDA (ATOUK-TEST-APP.APP::ENV) :IN "/src/lisp/atouk-test-app/app.lisp") (:LACK.SESSION.OPTIONS (:ID "0fc83f763b9b52531ac6923c277f91eb6759ee54" :NEW-SESSION T :CHANGE-ID NIL :EXPIRE NIL) :LACK.SESSION # :RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL))
8: ((LAMBDA (LACK.MIDDLEWARE.SESSION::ENV) :IN "/root/quicklisp/dists/quicklisp/software/lack-20161204-git/src/middleware/session.lisp") (:LACK.SESSION.OPTIONS (:ID "0fc83f763b9b52531ac6923c277f91eb6759ee54" :NEW-SESSION T :CHANGE-ID NIL :EXPIRE NIL) :LACK.SESSION # :RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL))
9: (LACK.UTIL:FUNCALL-WITH-CB # (:RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL) #)
10: ((LAMBDA (LACK.MIDDLEWARE.BACKTRACE::ENV) :IN "/root/quicklisp/dists/quicklisp/software/lack-20161204-git/src/middleware/backtrace.lisp") (:RAW-BODY # :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME NIL :SERVER-PORT 80 :SERVER-PROTOCOL :HTTP/1.1 :PATH-INFO "/login" :QUERY-STRING NIL :URL-SCHEME "http" :REMOTE-ADDR #1="172.18.0.1" :REMOTE-PORT 39658 :REQUEST-URI "/login" :CLACK.STREAMING T :CLACK.NONBLOCKING T :CLACK.IO #S(WOO.EV.SOCKET:SOCKET :WATCHERS #(#.(SB-SYS:INT-SAP #X7F036C011460) #.(SB-SYS:INT-SAP #X7F036C0114A0) #.(SB-SYS:INT-SAP #X7F036C0114E0)) :LAST-ACTIVITY 1.496378254617193d9 :FD 13 :REMOTE-ADDR #1# :REMOTE-PORT 39658 :DATA # :TCP-READ-CB WOO.EV.TCP::TCP-READ-CB :READ-CB # :WRITE-CB NIL :OPEN-P T :BUFFER #S(FAST-IO::OUTPUT-BUFFER :VECTOR #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :FILL 0 :LEN 0 :QUEUE NIL :LAST NIL :OUTPUT NIL) :SENDFILE-FD NIL :SENDFILE-SIZE 1213 :SENDFILE-OFFSET 1213) :CONTENT-LENGTH NIL :CONTENT-TYPE NIL :HEADERS # :BODY-PARAMETERS NIL :BODY-PARAMETERS NIL))
11: ((LAMBDA NIL :IN WOO::SETUP-PARSER))
12: ((LAMBDA (FAST-HTTP.HTTP:HTTP) :IN FAST-HTTP:MAKE-PARSER) #)
13: (FAST-HTTP.PARSER::PARSE-BODY #S(FAST-HTTP.HTTP:HTTP-REQUEST :METHOD :GET :MAJOR-VERSION 1 :MINOR-VERSION 1 :STATUS 0 :CONTENT-LENGTH NIL :CHUNKED-P NIL :UPGRADE-P NIL :HEADERS # :HEADER-READ 0 :MARK 382 :STATE 3 :RESOURCE "/login") # # # 382 #)
14: (FAST-HTTP.PARSER:PARSE-REQUEST #S(FAST-HTTP.HTTP:HTTP-REQUEST :METHOD :GET :MAJOR-VERSION 1 :MINOR-VERSION 1 :STATUS 0 :CONTENT-LENGTH NIL :CHUNKED-P NIL :UPGRADE-P NIL :HEADERS # :HEADER-READ 0 :MARK 382 :STATE 3 :RESOURCE "/login") #S(FAST-HTTP.PARSER:CALLBACKS :MESSAGE-BEGIN # :URL # :FIRST-LINE NIL :STATUS # :HEADER-FIELD # :HEADER-VALUE # :HEADERS-COMPLETE # :BODY # :MESSAGE-COMPLETE #) #(71 69 84 32 47 108 111 103 105 110 32 72 84 84 80 47 49 46 49 13 10 72 111 115 116 58 32 49 50 55 46 48 46 48 46 49 58 56 48 56 48 13 10 85 115 101 114 45 65 103 101 110 116 58 32 77 111 122 105 108 108 97 47 53 46 48 32 40 88 49 49 59 32 76 105 110 117 120 32 120 56 54 95 54 52 59 32 114 118 58 53 53 46 48 41 32 71 101 99 107 111 47 50 48 49 48 48 49 48 49 32 70 105 114 101 102 111 120 47 53 53 46 48 13 10 65 99 99 101 112 116 58 32 116 101 120 116 47 104 116 109 108 44 97 112 112 108 105 99 97 116 105 111 110 47 120 104 116 109 108 43 120 109 108 44 97 112 112 108 105 99 97 116 105 111 110 47 120 109 108 59 113 61 48 46 57 44 42 47 42 59 113 61 48 46 56 13 10 65 99 99 101 112 116 45 76 97 110 103 117 97 103 101 58 32 101 110 45 85 83 44 101 110 59 113 61 48 46 53 13 10 65 99 99 101 112 116 45 69 110 99 111 100 105 110 103 58 32 103 122 105 112 44 32 100 101 102 108 97 116 101 13 10 67 111 111 107 105 101 58 32 108 97 99 107 46 115 101 115 115 105 111 110 61 57 55 53 56 51 101 56 55 54 98 55 55 56 100 52 49 51 57 99 57 49 57 57 53 101 52 56 99 56 97 98 52 52 48 49 56 57 102 50 52 13 10 67 111 110 110 101 99 116 105 111 110 58 32 107 101 101 112 45 97 108 105 118 101 13 10 85 112 103 114 97 100 101 45 73 110 115 101 99 117 114 101 45 82 101 113 117 101 115 116 115 58 32 49 13 10 13 10 48 49 55 32 48 49 58 51 56 58 53 53 32 43 48 48 48 48 13 10 13 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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