mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
Fix buffer overrun with unbuffered custom binary input ports.
Fixes <http://bugs.gnu.org/19621>. Before that, in 'cbip_fill_input', BUFFERED would be set to 0 when reading from 'scm_getc' et al, because 'shortbuf' was being used. Thus, we could eventually execute this line: /* Copy the data back to the internal buffer. */ memcpy ((char *) c_port->read_pos, SCM_BYTEVECTOR_CONTENTS (bv), c_octets); But 'read_pos' would quickly point to the fields beyond 'shortbuf', thereby leading to a corruption of the 'scm_t_port' itself. * libguile/r6rs-ports.c (cbip_setvbuf): When READ_SIZE is 0, keep using BV as the 'read_buf'. (cbip_fill_input): Adjust assertion to accept 'read_buf_size = 1'. * test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports")["custom binary input port unbuffered & 'get-string-all'", "custom binary input port unbuffered UTF-8 & 'get-string-all'"]: New tests.
This commit is contained in:
parent
e1d29ee4f7
commit
ed72201a79
2 changed files with 42 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
;;;; r6rs-ports.test --- R6RS I/O port tests. -*- coding: utf-8; -*-
|
||||
;;;;
|
||||
;;;; Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 2009-2012, 2014-2015 Free Software Foundation, Inc.
|
||||
;;;; Ludovic Courtès
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
|
@ -557,6 +557,37 @@ not `set-port-position!'"
|
|||
obj))
|
||||
ret)))))
|
||||
|
||||
(pass-if-equal "custom binary input port unbuffered & 'get-string-all'"
|
||||
(make-string 1000 #\a)
|
||||
;; In Guile 2.0.11 this test would lead to a buffer overrun followed
|
||||
;; by an assertion failure. See <http://bugs.gnu.org/19621>.
|
||||
(let* ((input (with-fluids ((%default-port-encoding #f))
|
||||
(open-input-string (make-string 1000 #\a))))
|
||||
(read! (lambda (bv index count)
|
||||
(let ((n (get-bytevector-n! input bv index
|
||||
count)))
|
||||
(if (eof-object? n) 0 n))))
|
||||
(port (make-custom-binary-input-port "foo" read!
|
||||
#f #f #f)))
|
||||
(setvbuf port _IONBF)
|
||||
(get-string-all port)))
|
||||
|
||||
(pass-if-equal "custom binary input port unbuffered UTF-8 & 'get-string-all'"
|
||||
(make-string 1000 #\λ)
|
||||
;; In Guile 2.0.11 this test would lead to a buffer overrun followed
|
||||
;; by an assertion failure. See <http://bugs.gnu.org/19621>.
|
||||
(let* ((input (with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(open-input-string (make-string 1000 #\λ))))
|
||||
(read! (lambda (bv index count)
|
||||
(let ((n (get-bytevector-n! input bv index
|
||||
count)))
|
||||
(if (eof-object? n) 0 n))))
|
||||
(port (make-custom-binary-input-port "foo" read!
|
||||
#f #f #f)))
|
||||
(setvbuf port _IONBF)
|
||||
(set-port-encoding! port "UTF-8")
|
||||
(get-string-all port)))
|
||||
|
||||
(pass-if-equal "custom binary input port, unbuffered then buffered"
|
||||
`((6 "Lorem ") (12 "ipsum dolor ") (777 "sit amet, consectetur…")
|
||||
(777 ,(eof-object)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue