moriyoshi Mon Feb 24 17:47:15 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4/ext/standard php_string.h string.c
Log:
MFH: made strip_tags() binary safe
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.65.2.1 php4/ext/standard/php_string.h:1.65.2.2
--- php4/ext/standard/php_string.h:1.65.2.1 Tue Dec 31 11:35:33 2002
+++ php4/ext/standard/php_string.h Mon Feb 24 17:47:12 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_string.h,v 1.65.2.1 2002/12/31 16:35:33 sebastian Exp $ */
+/* $Id: php_string.h,v 1.65.2.2 2003/02/24 22:47:12 moriyoshi Exp $ */
/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
@@ -125,7 +125,7 @@
PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
int needle_len, char *str, int str_len, int *_new_length);
PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value,
int mode TSRMLS_DC);
-PHPAPI void php_strip_tags(char *rbuf, int len, int *state, char *allow, int
allow_len);
+PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int
allow_len);
PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval
*result);
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value);
PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit);
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.333.2.16 php4/ext/standard/string.c:1.333.2.17
--- php4/ext/standard/string.c:1.333.2.16 Tue Feb 18 13:14:32 2003
+++ php4/ext/standard/string.c Mon Feb 24 17:47:12 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.333.2.16 2003/02/18 18:14:32 moriyoshi Exp $ */
+/* $Id: string.c,v 1.333.2.17 2003/02/24 22:47:12 moriyoshi Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -3038,6 +3038,7 @@
zval **str, **allow=NULL;
char *allowed_tags=NULL;
int allowed_tags_len=0;
+ size_t retval_len;
switch (ZEND_NUM_ARGS()) {
case 1:
@@ -3059,8 +3060,8 @@
}
convert_to_string_ex(str);
buf = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
- php_strip_tags(buf, Z_STRLEN_PP(str), NULL, allowed_tags, allowed_tags_len);
- RETURN_STRING(buf, 0);
+ retval_len = php_strip_tags(buf, Z_STRLEN_PP(str), NULL, allowed_tags,
allowed_tags_len);
+ RETURN_STRINGL(buf, retval_len, 0);
}
/* }}} */
@@ -3294,7 +3295,7 @@
swm: Added ability to strip <?xml tags without assuming it PHP
code.
*/
-PHPAPI void php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int
allow_len)
+PHPAPI size_t php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int
allow_len)
{
char *tbuf, *buf, *p, *tp, *rp, c, lc;
int br, i=0, depth=0;
@@ -3484,12 +3485,16 @@
c = *(++p);
i++;
}
- *rp = '\0';
+ if (rp < rbuf + len) {
+ *rp = '\0';
+ }
efree(buf);
if (allow)
efree(tbuf);
if (stateptr)
*stateptr = state;
+
+ return (size_t)(rp - rbuf);
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php