| 498 | } |
| 499 | |
| 500 | static apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env, |
| 501 | int *errfd, cgid_req_t *req) |
| 502 | { |
| 503 | int i; |
| 504 | char **environ; |
| 505 | core_request_config *temp_core; |
| 506 | void **rconf; |
| 507 | apr_status_t stat; |
| 508 | |
| 509 | r->server = apr_pcalloc(r->pool, sizeof(server_rec)); |
| 510 | |
| 511 | /* read the request header */ |
| 512 | stat = sock_readhdr(fd, errfd, req, sizeof(*req)); |
| 513 | if (stat != APR_SUCCESS) { |
| 514 | return stat; |
| 515 | } |
| 516 | r->server->log.level = req->loglevel; |
| 517 | if (req->req_type == GETPID_REQ) { |
| 518 | /* no more data sent for this request */ |
| 519 | return APR_SUCCESS; |
| 520 | } |
| 521 | |
| 522 | /* Sanity check the structure received. */ |
| 523 | if (req->env_count < 0 || req->uri_len == 0 |
| 524 | || req->filename_len > APR_PATH_MAX || req->filename_len == 0 |
| 525 | || req->argv0_len > APR_PATH_MAX || req->argv0_len == 0 |
| 526 | || req->loglevel > APLOG_TRACE8) { |
| 527 | return APR_EINVAL; |
| 528 | } |
| 529 | |
| 530 | /* handle module indexes and such */ |
| 531 | rconf = (void **)ap_create_request_config(r->pool); |
| 532 | |
| 533 | temp_core = (core_request_config *)apr_palloc(r->pool, sizeof(core_module)); |
| 534 | rconf[AP_CORE_MODULE_INDEX] = (void *)temp_core; |
| 535 | r->request_config = (ap_conf_vector_t *)rconf; |
| 536 | ap_set_module_config(r->request_config, &cgid_module, (void *)&req->ugid); |
| 537 | |
| 538 | /* Read the filename, argv0, uri, and args */ |
| 539 | r->filename = apr_pcalloc(r->pool, req->filename_len + 1); |
| 540 | *argv0 = apr_pcalloc(r->pool, req->argv0_len + 1); |
| 541 | r->uri = apr_pcalloc(r->pool, req->uri_len + 1); |
| 542 | if ((stat = sock_read(fd, r->filename, req->filename_len)) != APR_SUCCESS || |
| 543 | (stat = sock_read(fd, *argv0, req->argv0_len)) != APR_SUCCESS || |
| 544 | (stat = sock_read(fd, r->uri, req->uri_len)) != APR_SUCCESS) { |
| 545 | return stat; |
| 546 | } |
| 547 | |
| 548 | r->args = apr_pcalloc(r->pool, req->args_len + 1); /* empty string if no args */ |
| 549 | if (req->args_len) { |
| 550 | if ((stat = sock_read(fd, r->args, req->args_len)) != APR_SUCCESS) { |
| 551 | return stat; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* read the environment variables */ |
| 556 | environ = apr_pcalloc(r->pool, (req->env_count + 2) *sizeof(char *)); |
| 557 | for (i = 0; i < req->env_count; i++) { |
no test coverage detected