]> granicus.if.org Git - php/commitdiff
emalloc -> safe_emalloc
authorIlia Alshanetsky <iliaa@php.net>
Mon, 11 Aug 2003 23:16:54 +0000 (23:16 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 11 Aug 2003 23:16:54 +0000 (23:16 +0000)
15 files changed:
ext/ereg/ereg.c
ext/standard/array.c
ext/standard/exec.c
ext/standard/file.c
ext/standard/filestat.c
ext/standard/formatted_print.c
ext/standard/levenshtein.c
ext/standard/metaphone.c
ext/standard/pack.c
ext/standard/reg.c
ext/standard/scanf.c
ext/standard/string.c
ext/standard/url.c
ext/standard/var.c
ext/standard/versioning.c

index eafc99be12fae391404431345b13c2d945d43ea2..b31c5f7d8544ca22dca3729697ef1a7ea108b055 100644 (file)
@@ -118,7 +118,7 @@ static void php_reg_eprint(int err, regex_t *re) {
        /* get the length of the message */
        buf_len = regerror(REG_ITOA | err, re, NULL, 0);
        if (buf_len) {
-               buf = (char *)emalloc(buf_len * sizeof(char));
+               buf = (char *)safe_emalloc(buf_len, sizeof(char), 0);
                if (!buf) return; /* fail silently */
                /* finally, get the error message */
                regerror(REG_ITOA | err, re, buf, buf_len);
@@ -130,7 +130,7 @@ static void php_reg_eprint(int err, regex_t *re) {
        if (len) {
                TSRMLS_FETCH();
 
-               message = (char *)emalloc((buf_len + len + 2) * sizeof(char));
+               message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0);
                if (!message) {
                        return; /* fail silently */
                }
@@ -298,7 +298,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
        /* start with a buffer that is twice the size of the stringo
           we're doing replacements in */
        buf_len = 2 * string_len + 1;
-       buf = emalloc(buf_len * sizeof(char));
+       buf = safe_emalloc(buf_len, sizeof(char), 0);
 
        err = pos = 0;
        buf[0] = '\0';
@@ -373,7 +373,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                                new_l = strlen (buf) + 1;
                                if (new_l + 1 > buf_len) {
                                        buf_len = 1 + buf_len + 2 * new_l;
-                                       nbuf = emalloc(buf_len * sizeof(char));
+                                       nbuf = safe_emalloc(buf_len, sizeof(char), 0);
                                        strcpy(nbuf, buf);
                                        efree(buf);
                                        buf = nbuf;
@@ -388,7 +388,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        new_l = strlen(buf) + strlen(&string[pos]);
                        if (new_l + 1 > buf_len) {
                                buf_len = new_l + 1; /* now we know exactly how long it is */
-                               nbuf = emalloc(buf_len * sizeof(char));
+                               nbuf = safe_emalloc(buf_len, sizeof(char), 0);
                                strcpy(nbuf, buf);
                                efree(buf);
                                buf = nbuf;
@@ -607,7 +607,7 @@ PHPAPI PHP_FUNCTION(sql_regcase)
        }       
        convert_to_string_ex(string);
        
-       tmp = emalloc((Z_STRLEN_PP(string) * 4) + 1);
+       tmp = safe_emalloc(Z_STRLEN_PP(string), 4, 1);
        
        for (i = j = 0; i < Z_STRLEN_PP(string); i++) {
                c = (unsigned char) Z_STRVAL_PP(string)[i];
index 0bcbc782e10f8840db55713b7ada1cf0df582590..335b4d54a272545735917cd5826679a078af2deb 100644 (file)
@@ -880,7 +880,7 @@ PHP_FUNCTION(min)
                        RETURN_FALSE;
                }
        } else {
-               pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS());
+               pval ***args = (pval ***) safe_emalloc(sizeof(pval **), ZEND_NUM_ARGS(), 0);
                pval **min, result;
                int i;
 
@@ -932,7 +932,7 @@ PHP_FUNCTION(max)
                        RETURN_FALSE;
                }
        } else {
-               pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS());
+               pval ***args = (pval ***) safe_emalloc(sizeof(pval **), ZEND_NUM_ARGS(), 0);
                pval **max, result;
                int i;
 
@@ -1419,7 +1419,7 @@ PHP_FUNCTION(compact)
        zval ***args;                   /* function arguments array */
        int i;
        
-       args = (zval ***)emalloc(ZEND_NUM_ARGS() * sizeof(zval **));
+       args = (zval ***)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval **), 0);
        
        if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
                efree(args);
@@ -1643,7 +1643,7 @@ static void array_data_shuffle(zval *array TSRMLS_DC)
                return;
        }
 
-       elems = (Bucket **)emalloc(n_elems * sizeof(Bucket *));
+       elems = (Bucket **)safe_emalloc(n_elems, sizeof(Bucket *), 0);
        hash = Z_ARRVAL_P(array);
        n_left = n_elems;
 
@@ -1818,7 +1818,7 @@ PHP_FUNCTION(array_push)
        }
        
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -1947,7 +1947,7 @@ PHP_FUNCTION(array_unshift)
        }
        
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -1997,7 +1997,7 @@ PHP_FUNCTION(array_splice)
        }
        
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -2026,7 +2026,7 @@ PHP_FUNCTION(array_splice)
                
                /* Create the array of replacement elements */
                repl_num = zend_hash_num_elements(Z_ARRVAL_PP(args[3]));
-               repl = (zval ***)emalloc(repl_num * sizeof(zval **));
+               repl = (zval ***)safe_emalloc(repl_num, sizeof(zval **), 0);
                for (p=Z_ARRVAL_PP(args[3])->pListHead, i=0; p; p=p->pListNext, i++) {
                        repl[i] = ((zval **)p->pData);
                }
@@ -2204,7 +2204,7 @@ static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive)
        }
        
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -2503,7 +2503,7 @@ PHP_FUNCTION(array_pad)
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time");
                RETURN_FALSE;
        }
-       pads = (zval ***)emalloc(num_pads * sizeof(zval **));
+       pads = (zval ***)safe_emalloc(num_pads, sizeof(zval **), 0);
        for (i = 0; i < num_pads; i++) {
                pads[i] = pad_value;
        }
@@ -2711,14 +2711,14 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior)
                WRONG_PARAM_COUNT;
        }
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
        }
        /* for each argument, create and sort list with pointers to the hash buckets */
-       lists = (Bucket ***)emalloc(argc * sizeof(Bucket **));
-       ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **));
+       lists = (Bucket ***)safe_emalloc(argc, sizeof(Bucket **), 0);
+       ptrs = (Bucket ***)safe_emalloc(argc, sizeof(Bucket **), 0);
        set_compare_func(SORT_STRING TSRMLS_CC);
        for (i=0; i<argc; i++) {
                if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
@@ -2868,14 +2868,14 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior)
                WRONG_PARAM_COUNT;
        }
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
        }
        /* for each argument, create and sort list with pointers to the hash buckets */
-       lists = (Bucket ***)emalloc(argc * sizeof(Bucket **));
-       ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **));
+       lists = (Bucket ***)safe_emalloc(argc, sizeof(Bucket **), 0);
+       ptrs = (Bucket ***)safe_emalloc(argc, sizeof(Bucket **), 0);
        set_compare_func(SORT_STRING TSRMLS_CC);
        for (i = 0; i < argc; i++) {
                if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
@@ -3061,7 +3061,7 @@ PHP_FUNCTION(array_multisort)
        }
        
        /* Allocate arguments array and get the arguments, checking for errors. */
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -3163,9 +3163,9 @@ PHP_FUNCTION(array_multisort)
         * of the input arrays + 1. The last column is NULL to indicate the end
         * of the row.
         */
-       indirect = (Bucket ***)emalloc(array_size * sizeof(Bucket **));
+       indirect = (Bucket ***)safe_emalloc(array_size, sizeof(Bucket **), 0);
        for (i = 0; i < array_size; i++)
-               indirect[i] = (Bucket **)emalloc((num_arrays+1) * sizeof(Bucket *));
+               indirect[i] = (Bucket **)safe_emalloc((num_arrays+1), sizeof(Bucket *), 0);
        
        for (i = 0; i < num_arrays; i++) {
                k = 0;
index eda62caf1ce5dc8367e8cfbe53b04b5973c8753f..671f6ffd14be7a86421772fec366bdf34661a64a 100644 (file)
@@ -263,7 +263,7 @@ char *php_escape_shell_cmd(char *str) {
        char *p = NULL;
 
        l = strlen(str);
-       cmd = emalloc(2 * l + 1);
+       cmd = safe_emalloc(2, l, 1);
        
        for (x = 0, y = 0; x < l; x++) {
                switch (str[x]) {
@@ -320,7 +320,7 @@ char *php_escape_shell_arg(char *str) {
        y = 0;
        l = strlen(str);
        
-       cmd = emalloc(4 * l + 3); /* worst case */
+       cmd = safe_emalloc(4, l, 3); /* worst case */
        
        cmd[y++] = '\'';
        
index 6b5c9a30ba9d2733b99d9eebb5d8a81a9450fb0b..b59c79a802a6f384e5006b8c2594a2178bf4d36d 100644 (file)
@@ -953,7 +953,7 @@ PHPAPI PHP_FUNCTION(fgetc)
 
        php_stream_from_zval(stream, arg1);
 
-       buf = emalloc(2 * sizeof(char));
+       buf = safe_emalloc(2, sizeof(char), 0);
 
        result = php_stream_getc(stream);
 
@@ -1019,7 +1019,7 @@ PHPAPI PHP_FUNCTION(fgetss)
                }
 
                len = (size_t) Z_LVAL_PP(bytes);
-               buf = emalloc(sizeof(char) * (len + 1));
+               buf = safe_emalloc(sizeof(char), (len + 1), 0);
                /*needed because recv doesnt set null char at end*/
                memset(buf, 0, len + 1);
        }
@@ -1055,7 +1055,7 @@ PHP_FUNCTION(fscanf)
        if (argCount < 2) {
                WRONG_PARAM_COUNT;
        }
-       args = (zval ***)emalloc(argCount * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argCount, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argCount, args) == FAILURE) {
                efree( args );
                WRONG_PARAM_COUNT;
index 6f83dc09a333ba5a97019ed7c51742a39b6456f3..184bf7c9745e0f8ae81eed5799df54d1feed791e 100644 (file)
@@ -644,7 +644,7 @@ static void php_stat(const char *filename, php_stat_len filename_length, int typ
 
                        groups = getgroups(0, NULL);
                        if(groups) {
-                               gids=(gid_t *)emalloc(groups*sizeof(gid_t));
+                               gids=(gid_t *)safe_emalloc(groups, sizeof(gid_t), 0);
                                n=getgroups(groups, gids);
                                for(i=0;i<n;i++){
                                        if(BG(sb).st_gid==gids[i]) {
index 83594a84003efbef293e9e069c44535d7e0c024a..4d141afc457c348c616b349aaf155bfc29589814 100644 (file)
@@ -471,7 +471,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
                        || (!use_array && argc < (1 + format_offset))) {
                WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
        }
-       args = (zval ***)emalloc(argc * sizeof(zval *));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval *), 0);
 
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
@@ -490,7 +490,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
                convert_to_array_ex(array);
                
                argc = 1 + zend_hash_num_elements(Z_ARRVAL_PP(array));
-               newargs = (zval ***)emalloc(argc * sizeof(zval *));
+               newargs = (zval ***)safe_emalloc(argc, sizeof(zval *), 0);
                newargs[0] = z_format;
                
                for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array));
index 1d447ef745c5169583d54df48e0fbed8e74eef03..bf99059b7fdcc7778935c09aa486ff80523cfc35 100644 (file)
@@ -40,10 +40,10 @@ static int reference_levdist(const char *s1, int l1,
        if((l1>LEVENSHTEIN_MAX_LENTH)||(l2>LEVENSHTEIN_MAX_LENTH))
                return -1;
 
-       if(!(p1=emalloc((l2+1)*sizeof(int)))) {
+       if(!(p1=safe_emalloc((l2+1), sizeof(int), 0))) {
                return -2;
        }
-       if(!(p2=emalloc((l2+1)*sizeof(int)))) {
+       if(!(p2=safe_emalloc((l2+1), sizeof(int), 0))) {
                free(p1);
                return -2;
        }
index db985c282e479448cb474e2a539f7087423f9f89..829164350e78eeb8ba067c305c7b01fa99e23ec1 100644 (file)
@@ -183,10 +183,10 @@ static int metaphone(char *word, int word_len, int max_phonemes, char **phoned_w
 /*-- Allocate memory for our phoned_phrase --*/
        if (max_phonemes == 0) {        /* Assume largest possible */
                max_buffer_len = word_len;
-               *phoned_word = emalloc(sizeof(char) * word_len + 1);
+               *phoned_word = safe_emalloc(sizeof(char), word_len, 1);
        } else {
                max_buffer_len = max_phonemes;
-               *phoned_word = emalloc(sizeof(char) * max_phonemes + 1);
+               *phoned_word = safe_emalloc(sizeof(char), max_phonemes, 1);
        }
 
 
index 8a5a97678ab6b21f72fe684f283193e9d944d7cc..5678ecbbf82f6df61ec2ff0103971e8a41411abd 100644 (file)
@@ -120,7 +120,7 @@ PHP_FUNCTION(pack)
                WRONG_PARAM_COUNT;
        }
 
-       argv = emalloc(argc * sizeof(zval **));
+       argv = safe_emalloc(argc, sizeof(zval **), 0);
 
        if (zend_get_parameters_array_ex(argc, argv) == FAILURE) {
                efree(argv);
@@ -132,8 +132,8 @@ PHP_FUNCTION(pack)
        formatlen = Z_STRLEN_PP(argv[0]);
 
        /* We have a maximum of <formatlen> format codes to deal with */
-       formatcodes = emalloc(formatlen * sizeof(*formatcodes));
-       formatargs = emalloc(formatlen * sizeof(*formatargs));
+       formatcodes = safe_emalloc(formatlen, sizeof(*formatcodes), 0);
+       formatargs = safe_emalloc(formatlen, sizeof(*formatargs), 0);
        currentarg = 1;
 
        /* Preprocess format into formatcodes and formatargs */
index eafc99be12fae391404431345b13c2d945d43ea2..b31c5f7d8544ca22dca3729697ef1a7ea108b055 100644 (file)
@@ -118,7 +118,7 @@ static void php_reg_eprint(int err, regex_t *re) {
        /* get the length of the message */
        buf_len = regerror(REG_ITOA | err, re, NULL, 0);
        if (buf_len) {
-               buf = (char *)emalloc(buf_len * sizeof(char));
+               buf = (char *)safe_emalloc(buf_len, sizeof(char), 0);
                if (!buf) return; /* fail silently */
                /* finally, get the error message */
                regerror(REG_ITOA | err, re, buf, buf_len);
@@ -130,7 +130,7 @@ static void php_reg_eprint(int err, regex_t *re) {
        if (len) {
                TSRMLS_FETCH();
 
-               message = (char *)emalloc((buf_len + len + 2) * sizeof(char));
+               message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0);
                if (!message) {
                        return; /* fail silently */
                }
@@ -298,7 +298,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
        /* start with a buffer that is twice the size of the stringo
           we're doing replacements in */
        buf_len = 2 * string_len + 1;
-       buf = emalloc(buf_len * sizeof(char));
+       buf = safe_emalloc(buf_len, sizeof(char), 0);
 
        err = pos = 0;
        buf[0] = '\0';
@@ -373,7 +373,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                                new_l = strlen (buf) + 1;
                                if (new_l + 1 > buf_len) {
                                        buf_len = 1 + buf_len + 2 * new_l;
-                                       nbuf = emalloc(buf_len * sizeof(char));
+                                       nbuf = safe_emalloc(buf_len, sizeof(char), 0);
                                        strcpy(nbuf, buf);
                                        efree(buf);
                                        buf = nbuf;
@@ -388,7 +388,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha
                        new_l = strlen(buf) + strlen(&string[pos]);
                        if (new_l + 1 > buf_len) {
                                buf_len = new_l + 1; /* now we know exactly how long it is */
-                               nbuf = emalloc(buf_len * sizeof(char));
+                               nbuf = safe_emalloc(buf_len, sizeof(char), 0);
                                strcpy(nbuf, buf);
                                efree(buf);
                                buf = nbuf;
@@ -607,7 +607,7 @@ PHPAPI PHP_FUNCTION(sql_regcase)
        }       
        convert_to_string_ex(string);
        
-       tmp = emalloc((Z_STRLEN_PP(string) * 4) + 1);
+       tmp = safe_emalloc(Z_STRLEN_PP(string), 4, 1);
        
        for (i = j = 0; i < Z_STRLEN_PP(string); i++) {
                c = (unsigned char) Z_STRVAL_PP(string)[i];
index a30f2671350cf8859f739a5fbbe305cc17023ad5..832272134e4d0de2c051446571c9130717d8600a 100644 (file)
@@ -175,9 +175,9 @@ static char * BuildCharSet(CharSet *cset, char *format)
                ch = end++;
        }
 
-       cset->chars = (char *) emalloc(sizeof(char) * (end - format - 1));
+       cset->chars = (char *) safe_emalloc(sizeof(char), (end - format - 1), 0);
        if (nranges > 0) {
-               cset->ranges = (struct Range *) emalloc(sizeof(struct Range)*nranges);
+               cset->ranges = (struct Range *) safe_emalloc(sizeof(struct Range), nranges, 0);
        } else {
                cset->ranges = NULL;
        }
@@ -337,7 +337,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
         */
 
        if (numVars > nspace) {
-               nassign = (int*)emalloc(sizeof(int) * numVars);
+               nassign = (int*)safe_emalloc(sizeof(int), numVars, 0);
                nspace = numVars;
        }
        for (i = 0; i < nspace; i++) {
@@ -513,7 +513,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
                                        nspace += STATIC_LIST_SIZE;
                                }
                                if (nassign == staticAssign) {
-                                       nassign = (void *)emalloc(nspace * sizeof(int));
+                                       nassign = (void *)safe_emalloc(nspace, sizeof(int), 0);
                                        for (i = 0; i < STATIC_LIST_SIZE; ++i) {
                                                nassign[i] = staticAssign[i];
                                        }
index c8fc17afef56f8e7f28c1d2ded30c77f13436ee1..ae1f71c36457fa2d1feecdabe45476d465fee9d2 100644 (file)
@@ -118,7 +118,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
        register unsigned char *result = NULL;
        size_t i, j;
 
-       result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1);
+       result = (char *) safe_emalloc(oldlen * 2, sizeof(char), 1);
        
        for (i = j = 0; i < oldlen; i++) {
                result[j++] = hexconvtab[old[i] >> 4];
@@ -1707,7 +1707,7 @@ static char *php_chunk_split(char *src, int srclen, char *end, int endlen, int c
        chunks = srclen / chunklen;
        restlen = srclen - chunks * chunklen; /* srclen % chunklen */
 
-       dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char));
+       dest = safe_emalloc((srclen + (chunks + 1) * endlen + 1), sizeof(char), 0);
 
        for (p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
                memcpy(q, p, chunklen);
@@ -2100,7 +2100,7 @@ PHP_FUNCTION(quotemeta)
                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;
@@ -2727,7 +2727,7 @@ PHPAPI void php_stripcslashes(char *str, int *len)
 PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_free, char *what, int wlength TSRMLS_DC)
 {
        char flags[256];
-       char *new_str = emalloc((length?length:(length=strlen(str)))*4+1); 
+       char *new_str = safe_emalloc(4, (length?length:(length=strlen(str))), 1);
        char *source, *target;
        char *end;
        char c;
@@ -2795,7 +2795,7 @@ PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_f
                *new_length = 0;
                return str;
        }
-       new_str = (char *) emalloc((length ? length : (length = strlen(str))) * 2 + 1);
+       new_str = (char *) safe_emalloc(2, (length ? length : (length = strlen(str))), 1);
        source = str;
        end = source + length;
        target = new_str;
@@ -2948,7 +2948,7 @@ PHPAPI char *php_str_to_str_ex(char *haystack, int length,
                        if (str_len < needle_len) {
                                new_str = emalloc(length + 1);
                        } else {
-                               new_str = emalloc((length / needle_len + 1) * str_len);
+                               new_str = safe_emalloc((length / needle_len + 1), str_len, 0);
                        }
 
                        e = s = new_str;
@@ -3553,7 +3553,7 @@ PHP_FUNCTION(strip_tags)
    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;
@@ -4409,7 +4409,7 @@ PHP_FUNCTION(sscanf)
                WRONG_PARAM_COUNT;
        }
 
-       args = (zval ***) emalloc(argc * sizeof(zval **));
+       args = (zval ***) safe_emalloc(argc, sizeof(zval **), 0);
        if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
index 541530c074d3913ca0eec7a5f786d2c137ef9135..3da9f66d940118522309a6a61ce5df22a39f62d8 100644 (file)
@@ -369,7 +369,7 @@ PHPAPI char *php_url_encode(char *s, int len, int *new_length)
        
        from = s;
        end = s + len;
-       start = to = (unsigned char *) emalloc(3 * len + 1);
+       start = to = (unsigned char *) safe_emalloc(3, len, 1);
 
        while (from < end) {
                c = *from++;
@@ -476,7 +476,7 @@ PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length)
        register int x, y;
        unsigned char *str;
 
-       str = (unsigned char *) emalloc(3 * len + 1);
+       str = (unsigned char *) safe_emalloc(3, len, 1);
        for (x = 0, y = 0; len--; x++, y++) {
                str[y] = (unsigned char) s[x];
 #ifndef CHARSET_EBCDIC
index eac33b05d3872ebd525de55112ab818bdc4317ed..a2fcdb4755246fe4a7451e28e57c3ee066554ad9 100644 (file)
@@ -141,7 +141,7 @@ PHP_FUNCTION(var_dump)
        
        argc = ZEND_NUM_ARGS();
        
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
@@ -245,7 +245,7 @@ PHP_FUNCTION(debug_zval_dump)
        
        argc = ZEND_NUM_ARGS();
        
-       args = (zval ***)emalloc(argc * sizeof(zval **));
+       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
        if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
                efree(args);
                WRONG_PARAM_COUNT;
index 6a259dc035e3549cacd393601b9f647b73ae1ea2..70c04dab05fbbb14dc86d4db5a218e8106a7d59e 100644 (file)
@@ -34,7 +34,7 @@ PHPAPI char *
 php_canonicalize_version(const char *version)
 {
     int len = strlen(version);
-    char *buf = emalloc(len * 2 + 1), *q, lp, lq;
+    char *buf = safe_emalloc(len, 2, 1), *q, lp, lq;
     const char *p;
 
     if (len == 0) {