From: Cyrill Gorcunov Date: Tue, 7 Sep 2010 16:31:11 +0000 (+0400) Subject: preproc.c: Make %substr robust X-Git-Tag: nasm-2.11.05~512 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cff031e1f7b280f9f663dae4922e80e71e724b3c;p=platform%2Fupstream%2Fnasm.git preproc.c: Make %substr robust Make %substr robust to handle -1,-1 parameters and restore old behavior when number of characters in substring is greater then length of string itself. Signed-off-by: Cyrill Gorcunov --- diff --git a/preproc.c b/preproc.c index c634992..70e550d 100644 --- a/preproc.c +++ b/preproc.c @@ -3449,13 +3449,14 @@ issue_error: len = nasm_unquote(t->text, NULL); - /* check the values provided, on error -- empty string */ + /* make start and count being in range */ + if (start < 0) + start = 0; if (count < 0) count = len + count + 1 - start; if (start + count > (int64_t)len) - start = -1; - - if (!len || count < 0 || start < 0) + count = len - start; + if (!len || count < 0 || start >=(int64_t)len) start = -1, count = 0; /* empty string */ macro_start = nasm_malloc(sizeof(*macro_start));