summaryrefslogtreecommitdiff
path: root/main/php_variables.c
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2003-03-27 21:13:47 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2003-03-27 21:13:47 +0000
commit961ad8e24a82a9543cf196d81106451b3138afb3 (patch)
tree880e9d2bd35ceb3cf0bb5a8ea054df6771fd62b8 /main/php_variables.c
parentf629da9384c717df45ed739eba85ea0e3978264e (diff)
downloadphp-git-961ad8e24a82a9543cf196d81106451b3138afb3.tar.gz
Improved php_import_environment_variables: avoid emalloc()ing in most cases
Diffstat (limited to 'main/php_variables.c')
-rw-r--r--main/php_variables.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/main/php_variables.c b/main/php_variables.c
index 1c7ee890a3..4be4d242b6 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -344,7 +344,11 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
{
- char **env, *p, *t;
+ char buf[128];
+ char **env, *p, *t = buf;
+ size_t alloc_size = sizeof(buf);
+ unsigned int nlen; /* ptrdiff_t is not portable */
+
/* turn off magic_quotes while importing environment variables */
int magic_quotes_gpc = PG(magic_quotes_gpc);
PG(magic_quotes_gpc) = 0;
@@ -354,8 +358,16 @@ void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
if (!p) { /* malformed entry? */
continue;
}
- t = estrndup(*env, p - *env);
+ nlen = p - *env;
+ if (nlen >= alloc_size) {
+ alloc_size = nlen + 64;
+ t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
+ }
+ memcpy(t, *env, nlen);
+ t[nlen] = '\0';
php_register_variable(t, p+1, array_ptr TSRMLS_CC);
+ }
+ if (t != buf && t != NULL) {
efree(t);
}
PG(magic_quotes_gpc) = magic_quotes_gpc;