MCPcopy Create free account
hub / github.com/apache/httpd / clean_env

Function clean_env

support/suexec.c:224–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224static void clean_env(void)
225{
226 char **cleanenv;
227 char **ep;
228 int cidx = 0;
229 int idx;
230
231 /* While cleaning the environment, the environment should be clean.
232 * (e.g. malloc() may get the name of a file for writing debugging info.
233 * Bad news if MALLOC_DEBUG_FILE is set to /etc/passwd. Sprintf() may be
234 * susceptible to bad locale settings....)
235 * (from PR 2790)
236 */
237 char **envp = environ;
238 char *empty_ptr = NULL;
239
240 environ = &empty_ptr; /* VERY safe environment */
241
242 if ((cleanenv = (char **) calloc(AP_ENVBUF, sizeof(char *))) == NULL) {
243 log_err("failed to malloc memory for environment\n");
244 exit(123);
245 }
246
247 cleanenv[cidx] = strdup("PATH=" AP_SAFE_PATH);
248 if (cleanenv[cidx] == NULL) {
249 log_err("failed to malloc memory for environment\n");
250 exit(124);
251 }
252 cidx++;
253
254 for (ep = envp; *ep && cidx < AP_ENVBUF-1; ep++) {
255 for (idx = 0; safe_env_lst[idx]; idx++) {
256 if (!strncmp(*ep, safe_env_lst[idx],
257 strlen(safe_env_lst[idx]))) {
258 cleanenv[cidx] = *ep;
259 cidx++;
260 break;
261 }
262 }
263 }
264
265 cleanenv[cidx] = NULL;
266
267 environ = cleanenv;
268}
269
270int main(int argc, char *argv[])
271{

Callers 1

mainFunction · 0.85

Calls 1

log_errFunction · 0.70

Tested by

no test coverage detected