Branch: Tag:

2008-06-23

2008-06-23 18:56:34 by Martin Stjernholm <mast@lysator.liu.se>

Fixed allocation bug in init_string_builder_copy. This could cause
memory corruption in String.Buffer when using `+ on overallocated
buffers.

Also ensure proper wide NUL termination in wide string builders.

Rev: src/stralloc.c:1.172

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: stralloc.c,v 1.171 2006/03/14 17:39:03 grubba Exp $ + || $Id: stralloc.c,v 1.172 2008/06/23 18:56:34 mast Exp $   */      #include "global.h"
24:   #include <ctype.h>   #include <math.h>    - RCSID("$Id: stralloc.c,v 1.171 2006/03/14 17:39:03 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.172 2008/06/23 18:56:34 mast Exp $");      /* #define STRALLOC_USE_PRIMES */   
1987:    s->malloced=256;    s->s=begin_wide_shared_string(256,mag);    s->s->len=0; -  s->s->str[0] = 0; +  low_set_index (s->s, 0, 0);    s->known_shift=0;   }   
1996:    s->malloced=length;    s->s=begin_wide_shared_string(length,mag);    s->s->len=0; -  s->s->str[0] = 0; +  low_set_index (s->s, 0, 0);    s->known_shift=0;   }   
2004:    struct string_builder *from)   {    to->malloced = from->malloced; -  to->s = begin_wide_shared_string (from->s->len, from->s->size_shift); -  MEMCPY (to->s->str, from->s->str, from->s->len << from->s->size_shift); +  to->s = begin_wide_shared_string (from->malloced, from->s->size_shift); +  to->s->len = from->s->len; +  MEMCPY (to->s->str, from->s->str, (from->s->len + 1) << from->s->size_shift);    to->known_shift = from->known_shift;   }   
2209:    s->known_shift=0;    s->s->len=0;    /* Ensure NUL-termination */ -  s->s->str[0] = 0; +  low_set_index (s->s, 0, 0);   }      PMOD_EXPORT void free_string_builder(struct string_builder *s)