Skip to content

Commit

Permalink
mod_log_config: better handle invalid log file name
Browse files Browse the repository at this point in the history
if log file name is an invalid string, ap_server_root_relative will return NULL, which will result in SIGSEGV in ap_make_dirstr_parent
  • Loading branch information
thomasmey committed Jan 1, 2025
1 parent aee4aaf commit 92bcfa3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/loggers/mod_log_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1912,15 +1912,26 @@ static int log_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)

static int check_log_dir(apr_pool_t *p, server_rec *s, config_log_state *cls)
{
char *dir;
apr_finfo_t finfo;
apr_status_t rv;

if (!cls->fname || cls->fname[0] == '|' || !cls->directive) {
return OK;
}
else {
char *abs = ap_server_root_relative(p, cls->fname);
char *dir = ap_make_dirstr_parent(p, abs);
apr_finfo_t finfo;
const ap_directive_t *directive = cls->directive;
apr_status_t rv = apr_stat(&finfo, dir, APR_FINFO_TYPE, p);
char *abs = ap_server_root_relative(p, cls->fname);
if (!abs) {
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, s,
APLOGNO(02297)
"Cannot construct log file path '%s' "
"defined at %s:%d", cls->fname,
directive->filename, directive->line_num);
return !OK;
}
dir = ap_make_dirstr_parent(p, abs);
rv = apr_stat(&finfo, dir, APR_FINFO_TYPE, p);
cls->directive = NULL; /* Don't check this config_log_state again */
if (rv == APR_SUCCESS && finfo.filetype != APR_DIR)
rv = APR_ENOTDIR;
Expand Down

0 comments on commit 92bcfa3

Please sign in to comment.