Branch: Tag:

2013-12-04

2013-12-04 14:33:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>

String.Buffer: Improved robustness in add().

The argument checking in add() was broken for the case where the
buffer wasn't empty. Note that the similar code in addat() is correct.

3155:    struct Buffer_struct *str = THIS;    int init_from_arg0 = 0, j;    +  for (j=0; j < args; j++) { +  if (TYPEOF(Pike_sp[j-args]) == PIKE_T_STRING) { +  } else if ((TYPEOF(Pike_sp[j-args]) != PIKE_T_OBJECT) || +  (Pike_sp[j-args].u.object->prog != Buffer_program)) { +  SIMPLE_BAD_ARG_ERROR("add", j+1, "string|String.Buffer"); +  } +  } +     if (!str->str.s && args) {    ptrdiff_t sum = 0;    int shift = 0;
3162:    struct pike_string *a;    if (TYPEOF(Pike_sp[j-args]) == PIKE_T_STRING) {    a = Pike_sp[j-args].u.string; -  } else if ((TYPEOF(Pike_sp[j-args]) != PIKE_T_OBJECT) || -  (Pike_sp[j-args].u.object->prog != Buffer_program)) { -  SIMPLE_BAD_ARG_ERROR("add", j+1, "string|String.Buffer"); +     } else {    a = OBJ2_BUFFER(Pike_sp[j-args].u.object)->str.s;    if (!a) continue;