diff options
author | William A. Rowe Jr <wrowe@apache.org> | 2002-03-16 19:26:58 +0100 |
---|---|---|
committer | William A. Rowe Jr <wrowe@apache.org> | 2002-03-16 19:26:58 +0100 |
commit | 65a37752ec30e81ebf8b41d679fd031a23b45f84 (patch) | |
tree | c386dd974ba944fc1e55885cbcae317077bf390c /server | |
parent | Silly module, we don't need compat.h :) (diff) | |
download | apache2-65a37752ec30e81ebf8b41d679fd031a23b45f84.tar.xz apache2-65a37752ec30e81ebf8b41d679fd031a23b45f84.zip |
Eliminate potential ap_server_root_relative segfaults, with the input
of Jeff Trawick's style changes to the first patches. Doesn't include
the fixes to ssl [more complex], and we won't trap errors that involve
ap_serverroot, since we presume that was normalized on the way in.
Therefore, testing ap_server_root_relative(DEFAULT_FOO) cases
should never become necessary.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93965 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r-- | server/config.c | 19 | ||||
-rw-r--r-- | server/core.c | 21 | ||||
-rw-r--r-- | server/log.c | 31 | ||||
-rw-r--r-- | server/mpm_common.c | 15 | ||||
-rw-r--r-- | server/scoreboard.c | 7 |
5 files changed, 68 insertions, 25 deletions
diff --git a/server/config.c b/server/config.c index e2f3578529..037f88b3a9 100644 --- a/server/config.c +++ b/server/config.c @@ -1209,11 +1209,17 @@ AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_pt * This allows most args to be independent of server_root, * so the server can be moved or mirrored with less pain. */ - const char *p; + const char *path; int offset = (int)(long)cmd->info; - p = ap_server_root_relative(cmd->pool, arg); - *(const char **) ((char*)struct_ptr + offset) = p; + path = ap_server_root_relative(cmd->pool, arg); + + if (!path) { + return apr_pstrcat(cmd->pool, "Invalid file path ", + arg, NULL); + } + + *(const char **) ((char*)struct_ptr + offset) = path; return NULL; } @@ -1757,6 +1763,13 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp, */ confname = ap_server_root_relative(p, filename); + if (!confname) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, + APR_EBADPATH, NULL, "Invalid config file path %s", + filename); + exit(1); + } + ap_process_resource_config(s, confname, conftree, p, ptemp); process_command_config(s, ap_server_post_read_config, conftree, diff --git a/server/core.c b/server/core.c index 279463caa5..7fb15c518f 100644 --- a/server/core.c +++ b/server/core.c @@ -1364,15 +1364,15 @@ static const char *set_etag_bits(cmd_parms *cmd, void *mconfig, bit = ETAG_INODE; } else { - return ap_pstrcat(cmd->pool, "Unknown keyword '", - token, "' for ", cmd->cmd->name, - " directive", NULL); + return apr_pstrcat(cmd->pool, "Unknown keyword '", + token, "' for ", cmd->cmd->name, + " directive", NULL); } if (! valid) { - return ap_pstrcat(cmd->pool, cmd->cmd->name, " keyword '", - token, "' cannot be used with '+' or '-'", - NULL); + return apr_pstrcat(cmd->pool, cmd->cmd->name, " keyword '", + token, "' cannot be used with '+' or '-'", + NULL); } if (action == '+') { @@ -2126,9 +2126,14 @@ static const char *include_config (cmd_parms *cmd, void *dummy, const char *name) { ap_directive_t *conftree = NULL; + const char* conffile = ap_server_root_relative(cmd->pool, name); + + if (!conffile) { + return apr_pstrcat(cmd->pool, "Invalid Include path ", + name, NULL); + } - ap_process_resource_config(cmd->server, - ap_server_root_relative(cmd->pool, name), + ap_process_resource_config(cmd->server, conffile, &conftree, cmd->pool, cmd->temp_pool); *(ap_directive_t **)dummy = conftree; return NULL; diff --git a/server/log.c b/server/log.c index c8edf972f3..5198f7003e 100644 --- a/server/log.c +++ b/server/log.c @@ -263,13 +263,18 @@ static void open_error_log(server_rec *s, apr_pool_t *p) #endif else { fname = ap_server_root_relative(p, s->error_fname); - rc = apr_file_open(&s->error_log, fname, - APR_APPEND | APR_READ | APR_WRITE | APR_CREATE, - APR_OS_DEFAULT, p); - if (rc != APR_SUCCESS) { + if (!fname) { + ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, + "%s: Invalid error log path %s.", + ap_server_argv0, s->error_fname); + exit(1); + } + if ((rc = apr_file_open(&s->error_log, fname, + APR_APPEND | APR_READ | APR_WRITE | APR_CREATE, + APR_OS_DEFAULT, p)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "%s: could not open error log file %s.", - ap_server_argv0, fname); + ap_server_argv0, s->error_fname); exit(1); } @@ -535,18 +540,26 @@ AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, va_end(args); } -AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname) +AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) { apr_file_t *pid_file = NULL; apr_finfo_t finfo; static pid_t saved_pid = -1; pid_t mypid; apr_status_t rv; + const char *fname; - if (!fname) - return; + if (!filename) { + return; + } + + fname = ap_server_root_relative(p, filename); + if (!fname) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH, + NULL, "Invalid PID file path %s, ignoring.", filename); + return; + } - fname = ap_server_root_relative(p, fname); mypid = getpid(); if (mypid != saved_pid && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) { diff --git a/server/mpm_common.c b/server/mpm_common.c index 71019dc296..dfe0f1939c 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -629,6 +629,7 @@ char ap_coredump_dir[MAX_STRING_LEN]; const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, const char *arg) { + apr_status_t rv; apr_finfo_t finfo; const char *fname; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -637,12 +638,18 @@ const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, } fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { + if (!fname) { + return apr_pstrcat(cmd->pool, "Invalid CoreDumpDirectory path ", + arg, NULL); + } + if ((rv = apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool)) != APR_SUCCESS) { return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); + " does not exist", NULL); + } + if (finfo.filetype != APR_DIR) { + return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, + " is not a directory", NULL); } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); return NULL; } diff --git a/server/scoreboard.c b/server/scoreboard.c index bbfdcf8097..b1f5b69264 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -213,7 +213,12 @@ static apr_status_t open_scoreboard(apr_pool_t *pconf) if (ap_scoreboard_fname) { /* make sure it's an absolute pathname */ fname = ap_server_root_relative(pconf, ap_scoreboard_fname); - + if (!fname) { + ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EBADPATH, NULL, + "Fatal error: Invalid Scoreboard path %s", + ap_scoreboard_fname); + return APR_EBADPATH; + } return create_namebased_scoreboard(global_pool, fname); } else { /* config didn't specify, we get to choose shmem type */ |