mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-13 07:10:20 +02:00
fix error handling in read-{request,response}-body/latin-1
* module/web/request.scm (read-request-body/latin-1): * module/web/response.scm (read-response-body/latin-1): Detect short reads instead of returning a full buffer with the last bits zeroed out. (Before the make-string commit, they contained uninitialized memory, which was a fairly serious error.)
This commit is contained in:
parent
3ef6650def
commit
f3d390939b
2 changed files with 12 additions and 6 deletions
|
@ -195,9 +195,12 @@
|
||||||
(define (read-request-body/latin-1 r)
|
(define (read-request-body/latin-1 r)
|
||||||
(let ((nbytes (request-content-length r)))
|
(let ((nbytes (request-content-length r)))
|
||||||
(and nbytes
|
(and nbytes
|
||||||
(let ((buf (make-string nbytes)))
|
(let* ((buf (make-string nbytes))
|
||||||
(read-delimited! "" buf (request-port r))
|
(n (read-delimited! "" buf (request-port r))))
|
||||||
buf))))
|
(if (= n nbytes)
|
||||||
|
buf
|
||||||
|
(bad-request "EOF while reading request body: ~a bytes of ~a"
|
||||||
|
n nbytes))))))
|
||||||
|
|
||||||
;; Likewise, assumes that body can be written in the latin-1 encoding,
|
;; Likewise, assumes that body can be written in the latin-1 encoding,
|
||||||
;; and that the latin-1 encoding is what is expected by the server.
|
;; and that the latin-1 encoding is what is expected by the server.
|
||||||
|
|
|
@ -187,9 +187,12 @@
|
||||||
(define (read-response-body/latin-1 r)
|
(define (read-response-body/latin-1 r)
|
||||||
(let ((nbytes (response-content-length r)))
|
(let ((nbytes (response-content-length r)))
|
||||||
(and nbytes
|
(and nbytes
|
||||||
(let ((buf (make-string nbytes)))
|
(let* ((buf (make-string nbytes))
|
||||||
(read-delimited! "" buf (response-port r))
|
(n (read-delimited! "" buf (response-port r))))
|
||||||
buf))))
|
(if (= n nbytes)
|
||||||
|
buf
|
||||||
|
(bad-response "EOF while reading response body: ~a bytes of ~a"
|
||||||
|
n nbytes))))))
|
||||||
|
|
||||||
;; Likewise, assumes that body can be written in the latin-1 encoding,
|
;; Likewise, assumes that body can be written in the latin-1 encoding,
|
||||||
;; and that the latin-1 encoding is what is expected by the server.
|
;; and that the latin-1 encoding is what is expected by the server.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue