Browse Source

plug memory leak in sapi_putenv, by using setenv(), that doesnt need any malloc

PECL_OPENSSL
Nuno Lopes 20 years ago
parent
commit
6509311ebb
  1. 1
      configure.in
  2. 23
      sapi/cgi/cgi_main.c

1
configure.in

@ -505,6 +505,7 @@ scandir \
setitimer \
setlocale \
localeconv \
setenv \
setpgid \
setsockopt \
setvbuf \

23
sapi/cgi/cgi_main.c

@ -405,6 +405,18 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
return fcgi_putenv(request, name, name_len, value);
}
#endif
#if HAVE_SETENV
if (value) {
setenv(name, value, 1);
}
#endif
#if HAVE_UNSETENV
if (!value) {
unsetenv(name);
}
#endif
#if !HAVE_SETENV || !HAVE_UNSETENV
/* if cgi, or fastcgi and not found in fcgi env
check the regular environment
this leaks, but it's only cgi anyway, we'll fix
@ -415,12 +427,19 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
if (buf == NULL) {
return getenv(name);
}
#endif
#if !HAVE_SETENV
if (value) {
len = snprintf(buf, len - 1, "%s=%s", name, value);
} else {
putenv(buf);
}
#endif
#if !HAVE_UNSETENV
if (!value) {
len = snprintf(buf, len - 1, "%s=", name);
putenv(buf);
}
putenv(buf);
#endif
return getenv(name);
}

Loading…
Cancel
Save