From 3a067320e4c1d47e3be9cd30cdf6d2c22ad2c62b Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Sat, 31 Jan 2009 20:35:03 +0000 Subject: [PATCH] * Prevent segfaults in handlers by ensuring that r->handler != NULL. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@739598 13f79535-47bb-0310-9956-ffa450edef68 --- server/config.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/server/config.c b/server/config.c index 189cea5225..564cf6d5ef 100644 --- a/server/config.c +++ b/server/config.c @@ -324,6 +324,12 @@ static int ap_invoke_filter_init(ap_filter_t *filters) return OK; } +/* + * TODO: Move this to an appropriate include file and possibly prefix it + * with AP_. + */ +#define DEFAULT_HANDLER_NAME "" + AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r) { const char *handler; @@ -355,19 +361,24 @@ AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r) return result; } - if (!r->handler && r->content_type) { - handler = r->content_type; - if ((p=ap_strchr_c(handler, ';')) != NULL) { - char *new_handler = (char *)apr_pmemdup(r->pool, handler, - p - handler + 1); - char *p2 = new_handler + (p - handler); - handler = new_handler; + if (!r->handler) { + if (r->content_type) { + handler = r->content_type; + if ((p=ap_strchr_c(handler, ';')) != NULL) { + char *new_handler = (char *)apr_pmemdup(r->pool, handler, + p - handler + 1); + char *p2 = new_handler + (p - handler); + handler = new_handler; - /* exclude media type arguments */ - while (p2 > handler && p2[-1] == ' ') - --p2; /* strip trailing spaces */ + /* exclude media type arguments */ + while (p2 > handler && p2[-1] == ' ') + --p2; /* strip trailing spaces */ - *p2='\0'; + *p2='\0'; + } + } + else { + handler = DEFAULT_HANDLER_NAME; } r->handler = handler; -- 2.50.1