Skip to content

Commit e4f00c5

Browse files
committed
envvars from HTTP headers low precedence
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1930163 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6aa64b2 commit e4f00c5

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

server/util_script.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,45 @@ AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
126126
}
127127
}
128128
for (i = 0; i < env_arr->nelts; ++i) {
129+
int changed = 0;
130+
129131
if (!elts[i].key) {
130132
continue;
131133
}
132134
env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
133135
whack = env[j];
134136
if (apr_isdigit(*whack)) {
135137
*whack++ = '_';
138+
changed = 1;
136139
}
137140
while (*whack != '=') {
138141
#ifdef WIN32
139-
if (!apr_isalnum(*whack) && *whack != '(' && *whack != ')') {
142+
if (!apr_isalnum(*whack) && *whack != '_' && *whack != '(' && *whack != ')') {
140143
#else
141-
if (!apr_isalnum(*whack)) {
144+
if (!apr_isalnum(*whack) && *whack != '_') {
142145
#endif
143146
*whack = '_';
147+
changed = 1;
144148
}
145149
++whack;
146150
}
147-
++j;
151+
if (changed) {
152+
*whack = '\0';
153+
/*
154+
* If after cleaning up the key the key is identical to an existing key
155+
* in the table drop this environment variable. This also prevents
156+
* to override CGI reserved environment variables with variables whose
157+
* names have an invalid character instead of '_', but are otherwise
158+
* equal to the names CGI reserved environment variables.
159+
*/
160+
if (!apr_table_get(t, env[j])) {
161+
++j;
162+
*whack = '=';
163+
}
164+
}
165+
else {
166+
++j;
167+
}
148168
}
149169

150170
env[j] = NULL;

0 commit comments

Comments
 (0)