mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Prevent TOCTTOU bugs in C ports
* libguile/ports-internal.h (scm_port_buffer_can_take): (scm_port_buffer_can_put): Add cur/end output arguments so that when a caller asks the buffer room, it can be relative to a fixed point in the buffer and not whatever point it's at when we go to fill it. (scm_port_buffer_did_take, scm_port_buffer_did_put): Similarly, require that the caller knows where they took/put data in the buffer. Prevents overflow. (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): Likewise, require that the caller has already checked and knows a position in the buffer and therefore how much data is available. (scm_port_buffer_take, scm_port_buffer_put, scm_port_buffer_putback): Adapt. * libguile/ports.h (scm_fill_input): Add cur/avail output arguments. * libguile/filesys.c: * libguile/poll.c: * libguile/ports.c: * libguile/r6rs-ports.c: * libguile/read.c: * libguile/rw.c: Adapt all callers. Gnarly work!
This commit is contained in:
parent
8a4774dec8
commit
09a69dd712
8 changed files with 251 additions and 176 deletions
|
@ -232,6 +232,7 @@ SCM_DEFINE (scm_write_string_partial, "write-string/partial", 1, 3, 0,
|
|||
SCM port = (SCM_UNBNDP (port_or_fdes)?
|
||||
scm_current_output_port () : port_or_fdes);
|
||||
SCM write_buf;
|
||||
size_t end;
|
||||
|
||||
SCM_VALIDATE_OPFPORT (2, port);
|
||||
SCM_VALIDATE_OUTPUT_PORT (2, port);
|
||||
|
@ -239,7 +240,7 @@ SCM_DEFINE (scm_write_string_partial, "write-string/partial", 1, 3, 0,
|
|||
|
||||
/* Filling the last character in the buffer would require a
|
||||
flush. */
|
||||
if (write_len < scm_port_buffer_can_put (write_buf))
|
||||
if (write_len < scm_port_buffer_can_put (write_buf, &end))
|
||||
{
|
||||
scm_c_write (port, src, write_len);
|
||||
return scm_from_long (write_len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue