From edaecc9146dd2781a890abdc74e3d6ce0f618337 Mon Sep 17 00:00:00 2001 From: Nick Kew Date: Thu, 3 Apr 2008 00:34:20 +0000 Subject: [PATCH] Avoid returning NULL from ap_expr_string. Empty string works and won't cause segfault. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@644122 13f79535-47bb-0310-9956-ffa450edef68 --- server/util_expr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/util_expr.c b/server/util_expr.c index a9a6640e6a..d2b92bb2dc 100644 --- a/server/util_expr.c +++ b/server/util_expr.c @@ -897,6 +897,7 @@ static ap_regex_t *isvar = NULL; AP_DECLARE(const char*) ap_expr_string(request_rec *r, const char *str) { /* a default string evaluator: support headers and env */ + const char *ret = str; ap_regmatch_t match[3]; ap_assert(isvar != NULL); if (ap_regexec(isvar, str, 3, match, 0) == 0) { @@ -915,20 +916,23 @@ AP_DECLARE(const char*) ap_expr_string(request_rec *r, const char *str) if (table != NULL) { char *key = apr_pstrndup(r->pool, str+match[2].rm_so, match[2].rm_eo-match[2].rm_so); - return apr_table_get(table, key); + ret = apr_table_get(table, key); } } else if (str[0] == '$') { if (!strcasecmp(str, "$handler")) { - return r->handler; + ret = r->handler; } else if (!strcasecmp(str, "$content-type")) { - return r->content_type; + ret = r->content_type; } } /* TODO: provide a hook so modules can interpret other patterns */ /* OhBugger, where's the regexp for backreferences ? */ - return str; /* default - literal string as-is */ + if (!ret) { + ret = ""; + } + return ret; /* default - literal string as-is */ } static apr_status_t ap_expr_term(void *expr) { -- 2.50.1