From e05bb40e074fed7fc8d2ae8d0cc9a01da988cb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Wed, 4 Dec 2013 15:33:43 +0100 Subject: [PATCH] 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. --- src/builtin.cmod | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/builtin.cmod b/src/builtin.cmod index 4895c8271f..1143bc625a 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -3155,6 +3155,14 @@ PIKECLASS Buffer 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,9 +3170,6 @@ PIKECLASS Buffer 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; -- GitLab