From: Jeroen van Wolffelaar Date: Sun, 5 Aug 2001 19:38:49 +0000 (+0000) Subject: Error-handling for the second parameter of [l|r]trim X-Git-Tag: PRE_ENGINE2_SPLIT~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a01a15fd292bb8a442b91158dfef1da099a6537;p=php Error-handling for the second parameter of [l|r]trim --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 0ca7ac5f91..8dd300951a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -406,22 +406,48 @@ PHP_FUNCTION(strcoll) /* {{{ php_charmask * Fills a 256-byte bytemask with input. You can specify a range like 'a..z', * it needs to be incrementing. + * Returns: FAILURE/SUCCESS wether the input was correct (i.e. no range errors) */ -void php_charmask(unsigned char *input, int len, char *mask) +int php_charmask(unsigned char *input, int len, char *mask) { unsigned char *end; unsigned char c; + int result = SUCCESS; memset(mask, 0, 256); for (end=input+len; input= c) { - memset(mask+c, 1, *(input+3) - c + 1); + if (input+3= c) { + memset(mask+c, 1, input[3] - c + 1); input+=3; - } else + } else if (input+1=input) { /* there was no 'left' char */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), no character to the left of '..'",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + if (input+2>=end) { /* there is no 'right' char */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), no character to the right of '..'",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + if (input[-1] > input[2]) { /* wrong order */ + php_error(E_WARNING,"Invalid '..'-range passed to %s(), '..'-range needs to be incrementing",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } + /* FIXME: better error (a..b..c is the only left possibility?) */ + php_error(E_WARNING,"Invalid '..'-range passed to %s()",get_active_function_name(TSRMLS_C)); + result = FAILURE; + continue; + } else { mask[c]=1; + } } + return result; } /* }}} */