diff --git a/NEWS b/NEWS index 077a83d3..db3189f2 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,7 @@ NEWS * Use filedescriptor 0 for mod_scgi spawn socket, redirect STDERR to /dev/null (#1716) * fixed round-robin balancing in mod_proxy (#1715) * fixed EINTR handling for waitpid in mod_fastcgi + * mod_{fast,s}cgi: overwrite environment variables (#1722) - 1.4.19 - 2008-03-10 diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index edc18fa8..22940c09 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -703,6 +703,7 @@ FREE_FUNC(mod_fastcgi_free) { static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) { char *dst; + size_t i; if (!key || !val) return -1; @@ -712,6 +713,15 @@ static int env_add(char_array *env, const char *key, size_t key_len, const char /* add the \0 from the value */ memcpy(dst + key_len + 1, val, val_len + 1); + for (i = 0; i < env->used; i++) { + if (0 == strncmp(dst, env->ptr[i], key_len + 1)) { + /* don't care about free as we are in a forked child which is going to exec(...) */ + /* free(env->ptr[i]); */ + env->ptr[i] = dst; + return 0; + } + } + if (env->size == 0) { env->size = 16; env->ptr = malloc(env->size * sizeof(*env->ptr)); diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 01d1f159..e6f17541 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -593,6 +593,7 @@ FREE_FUNC(mod_scgi_free) { static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) { char *dst; + size_t i; if (!key || !val) return -1; @@ -602,6 +603,15 @@ static int env_add(char_array *env, const char *key, size_t key_len, const char /* add the \0 from the value */ memcpy(dst + key_len + 1, val, val_len + 1); + for (i = 0; i < env->used; i++) { + if (0 == strncmp(dst, env->ptr[i], key_len + 1)) { + /* don't care about free as we are in a forked child which is going to exec(...) */ + /* free(env->ptr[i]); */ + env->ptr[i] = dst; + return 0; + } + } + if (env->size == 0) { env->size = 16; env->ptr = malloc(env->size * sizeof(*env->ptr));