cvs: php4(PHP_4_3) /ext/standard string.c

From: Date: Wed, 16 Apr 2003 23:49:45 +0000
Subject: cvs: php4(PHP_4_3) /ext/standard string.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20347@lists.php.net to get a copy of this message
iliaa Wed Apr 16 19:49:45 2003 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard string.c Log: safe_emalloc() and few other integer overflow fixes. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.333.2.22 php4/ext/standard/string.c:1.333.2.23 --- php4/ext/standard/string.c:1.333.2.22 Tue Apr 15 21:07:20 2003 +++ php4/ext/standard/string.c Wed Apr 16 19:49:45 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.333.2.22 2003/04/16 01:07:20 iliaa Exp $ */ +/* $Id: string.c,v 1.333.2.23 2003/04/16 23:49:45 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -112,10 +112,7 @@ register unsigned char *result = NULL; size_t i, j; - result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1); - if (!result) { - return result; - } + result = safe_emalloc(sizeof(char), oldlen * 2, 1); for (i = j = 0; i < oldlen; i++) { result[j++] = hexconvtab[old[i] >> 4]; @@ -677,6 +674,9 @@ chk = textlen; alloced = textlen * (breakcharlen + 1) + 1; } + if (alloced <= 0) { + RETURN_FALSE; + } newtext = emalloc(alloced); /* now keep track of the actual new text length */ @@ -1553,7 +1553,7 @@ chunks = srclen / chunklen; restlen = srclen - chunks * chunklen; /* srclen % chunklen */ - dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char)); + dest = safe_emalloc(sizeof(char), (srclen + (chunks + 1) * endlen + 1), 0); for (p = src, q = dest; p < (src + srclen - chunklen + 1); ) { memcpy(q, p, chunklen); @@ -1773,7 +1773,7 @@ RETURN_FALSE; } - str = emalloc(2 * Z_STRLEN_PP(arg) + 1); + str = safe_emalloc(2, Z_STRLEN_PP(arg), 1); for (p = old, q = str; p != old_end; p++) { c = *p; @@ -2997,7 +2997,10 @@ RETURN_STRINGL(Z_STRVAL_PP(zstr), Z_STRLEN_PP(zstr), 1); } - new_length = Z_STRLEN_PP(zstr) + repl_cnt * (sizeof("<br />") - 1); + if ((new_length = Z_STRLEN_PP(zstr) + repl_cnt * (sizeof("<br />") - 1)) < 0) { + RETURN_FALSE; + } + tmp = target = emalloc(new_length + 1); str = Z_STRVAL_PP(zstr); @@ -3070,7 +3073,7 @@ Set locale information */ PHP_FUNCTION(setlocale) { - pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); + pval ***args = (pval ***) safe_emalloc(sizeof(pval **), ZEND_NUM_ARGS(), 0); zval **pcategory, **plocale; int i, cat, n_args=ZEND_NUM_ARGS(); char *loc, *retval; @@ -3534,7 +3537,7 @@ /* Initialize the result string */ result_len = Z_STRLEN_PP(input_str) * Z_LVAL_PP(mult); - if (result_len < 1 || result_len > 2147483647) { + if (result_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may not create strings longer then 2147483647 bytes"); RETURN_FALSE; } @@ -3913,7 +3916,7 @@ WRONG_PARAM_COUNT; } - args = (zval ***) emalloc(argc * sizeof(zval **)); + args = (zval ***) safe_emalloc(sizeof(zval **), argc, 0); if (zend_get_parameters_array_ex(argc, args) == FAILURE) { efree(args); WRONG_PARAM_COUNT;

« previous php.cvs (#20347) next »