1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +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:
Andy Wingo 2010-12-04 19:45:09 +01:00
parent 3ef6650def
commit f3d390939b
2 changed files with 12 additions and 6 deletions

View file

@ -195,9 +195,12 @@
(define (read-request-body/latin-1 r)
(let ((nbytes (request-content-length r)))
(and nbytes
(let ((buf (make-string nbytes)))
(read-delimited! "" buf (request-port r))
buf))))
(let* ((buf (make-string nbytes))
(n (read-delimited! "" buf (request-port r))))
(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,
;; and that the latin-1 encoding is what is expected by the server.

View file

@ -187,9 +187,12 @@
(define (read-response-body/latin-1 r)
(let ((nbytes (response-content-length r)))
(and nbytes
(let ((buf (make-string nbytes)))
(read-delimited! "" buf (response-port r))
buf))))
(let* ((buf (make-string nbytes))
(n (read-delimited! "" buf (response-port r))))
(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,
;; and that the latin-1 encoding is what is expected by the server.