| 507 | } |
| 508 | |
| 509 | static int cgi_handler(request_rec *r) |
| 510 | { |
| 511 | int nph; |
| 512 | apr_size_t dbufsize; |
| 513 | const char *argv0; |
| 514 | const char *command; |
| 515 | const char **argv; |
| 516 | char *dbuf = NULL; |
| 517 | apr_file_t *script_out = NULL, *script_in = NULL, *script_err = NULL; |
| 518 | conn_rec *c = r->connection; |
| 519 | apr_bucket_brigade *bb = apr_brigade_create(r->pool, c->bucket_alloc); |
| 520 | apr_bucket *b; |
| 521 | int is_included; |
| 522 | apr_pool_t *p; |
| 523 | cgi_server_conf *conf; |
| 524 | apr_status_t rv; |
| 525 | cgi_exec_info_t e_info; |
| 526 | cgi_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgi_module); |
| 527 | apr_interval_time_t timeout = dc->timeout > 0 ? dc->timeout : r->server->timeout; |
| 528 | |
| 529 | if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) { |
| 530 | return DECLINED; |
| 531 | } |
| 532 | |
| 533 | is_included = !strcmp(r->protocol, "INCLUDED"); |
| 534 | |
| 535 | p = r->main ? r->main->pool : r->pool; |
| 536 | |
| 537 | argv0 = apr_filepath_name_get(r->filename); |
| 538 | nph = !(strncmp(argv0, "nph-", 4)); |
| 539 | conf = ap_get_module_config(r->server->module_config, &cgi_module); |
| 540 | |
| 541 | if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r)) |
| 542 | return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02809), |
| 543 | "Options ExecCGI is off in this directory"); |
| 544 | if (nph && is_included) |
| 545 | return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02810), |
| 546 | "attempt to include NPH CGI script"); |
| 547 | |
| 548 | if (r->finfo.filetype == APR_NOFILE) |
| 549 | return log_scripterror(r, conf, HTTP_NOT_FOUND, 0, APLOGNO(02811), |
| 550 | "script not found or unable to stat"); |
| 551 | if (r->finfo.filetype == APR_DIR) |
| 552 | return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02812), |
| 553 | "attempt to invoke directory as script"); |
| 554 | |
| 555 | if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) && |
| 556 | r->path_info && *r->path_info) |
| 557 | { |
| 558 | /* default to accept */ |
| 559 | return log_scripterror(r, conf, HTTP_NOT_FOUND, 0, APLOGNO(02813), |
| 560 | "AcceptPathInfo off disallows user's path"); |
| 561 | } |
| 562 | /* |
| 563 | if (!ap_suexec_enabled) { |
| 564 | if (!ap_can_exec(&r->finfo)) |
| 565 | return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(03194) |
| 566 | "file permissions deny server execution"); |
nothing calls this directly
no test coverage detected