-
Notifications
You must be signed in to change notification settings - Fork 12
Add *MAX-LINE-LENGTH* and *MAX-HEADER-LINE-LENGTH* #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,3 +82,13 @@ Read character ~S, but expected ~:[a member of ~S~;~S~]." | |
| (:documentation "A condition of this type is signaled if an | ||
| unexpected character \(octet) is read while reading from a chunked | ||
| stream with input chunking enabled.")) | ||
|
|
||
| (define-condition input-exceeded-limit (chunga-error) | ||
| ((maximum :initarg :maximum | ||
| :documentation "The limit which was exceeded.")) | ||
| (:report (lambda (condition stream) | ||
| (with-slots (maximum) | ||
| condition | ||
| (format stream "Input exceeded ~d characters." maximum)))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that format call will definitely be more efficient with at least one e.g. |
||
| (:documentation "A condition of this type is signaled if an | ||
| maximum-character limit is exceeded.")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,8 +100,11 @@ Additionally logs this string to LOG-STREAM if it is not NIL." | |
| (let ((result | ||
| (with-output-to-string (line) | ||
| (loop for char-seen-p = nil then t | ||
| for count from 0 | ||
|
||
| for char = (read-char* stream nil) | ||
| for is-cr-p = (and char (char= char #\Return)) | ||
| when (and *max-line-length* (> count *max-line-length*)) | ||
| do (error 'input-exceeded-limit :maximum *max-line-length*) | ||
|
||
| until (or (null char) | ||
| is-cr-p | ||
| (and *accept-bogus-eols* | ||
|
|
@@ -155,7 +158,8 @@ separated by commas. Header lines which are spread across | |
| multiple lines are recognized and treated correctly. Additonally | ||
| logs the header lines to LOG-STREAM if it is not NIL." | ||
| (let (headers | ||
| (*current-error-message* "While reading HTTP headers:")) | ||
| (*current-error-message* "While reading HTTP headers:") | ||
| (*max-line-length* (or *max-header-line-length* *max-line-length*))) | ||
| (labels ((read-header-line () | ||
| "Reads one header line, considering continuations." | ||
| (with-output-to-string (header-line) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,13 @@ variable has a true value, though.") | |
| "A `buffer' for one character. Used by PEEK-CHAR* and | ||
| UNREAD-CHAR*.") | ||
|
|
||
| (defvar *max-line-length* nil | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(cl:deftype chunga:maybe-pointer
'(or null fixnum) "I'm useless")The point of this PR is to provably bound memory consumption, and thus the type specifier must not allow any non-fixnum values. |
||
| "Maximum length of a line. If NIL, lines may be any length.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd appreciate more documentation. The docstring should address:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
why can't compilers rely on humans to read this out of #'cl:describe-object output? |
||
|
|
||
| (defvar *max-header-line-length* nil | ||
| "Maximum length of HTTP header lines. If NIL, defaults to | ||
| *MAX-LINE-LENGTH*.") | ||
|
|
||
| (pushnew :chunga *features*) | ||
|
|
||
| ;; stuff for Nikodemus Siivola's HYPERDOC | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should probably also get type-declared, if possible; some fascist implementations might like allocating conditions on the stack and bitch about boxed pointer safety garbage