Branch: Tag:

2015-05-16

2015-05-16 13:02:23 by Arne Goedeke <el@laramies.com>

Stdio.Buffer: io_ensure_malloced: use size_t type for 'bytes' input parameter.

Also adds an overflow check.

203:    }    }    -  static void io_ensure_malloced( Buffer *io, int bytes ) +  static void io_ensure_malloced( Buffer *io, size_t bytes )    {    if( UNLIKELY(!io->malloced) )    {
211:    if( !io_unstash_malloc(io) )    {    unsigned char *old = io->buffer; -  io->buffer = xalloc( io->len + bytes + 100 ); +  +  bytes += io->len; +  +  if (bytes < io->len || bytes + 100 < bytes) +  Pike_error(msg_out_of_mem_2, bytes + 100); +  +  bytes += 100; +  +  io->buffer = xalloc( bytes );    io->malloced = 1; -  io->allocated = io->len + bytes + 100; +  io->allocated = bytes;    io->num_malloc++;    memcpy( io->buffer, old, io->len );    io_unlink_external_storage(io);
286:   #else    new_len = round_up32(io->len+bytes);   #endif -  if( !new_len ) -  Pike_error(msg_out_of_mem_2, io->len+bytes); +  if (!new_len) new_len = io->len + bytes;       io->buffer = xrealloc( io->buffer, new_len );    io->num_malloc++;