]> granicus.if.org Git - apache/commitdiff
Avoid returning NULL from ap_expr_string.
authorNick Kew <niq@apache.org>
Thu, 3 Apr 2008 00:34:20 +0000 (00:34 +0000)
committerNick Kew <niq@apache.org>
Thu, 3 Apr 2008 00:34:20 +0000 (00:34 +0000)
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

index a9a6640e6aa91b02d0324eb2ce0fd0b0c3dcbe6a..d2b92bb2dc9056ac8e25f64ddd53730952509f83 100644 (file)
@@ -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)
 {