From 2077d6be0ab4dd30aa716d1ea7b5ad2a727b8d0d Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 9 Mar 2018 09:36:18 +0000 Subject: [PATCH] Follow up to r1609680: further simplify/optimize ap_proxy_strcmp_ematch(). While at it, same treatment for its mother ap_strcmp_match(). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1826313 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/proxy_util.c | 13 ++++++------- server/util.c | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 0a88c5bac7..ef692a5b49 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1502,10 +1502,7 @@ static int ap_proxy_strcmp_ematch(const char *str, const char *expected) apr_size_t x, y; for (x = 0, y = 0; expected[y]; ++y, ++x) { - int backref = (expected[y] == '$' && apr_isdigit(expected[y + 1])); - if (!str[x] && !backref) - return -1; - if (backref) { + if (expected[y] == '$' && apr_isdigit(expected[y + 1])) { do { y += 2; } while (expected[y] == '$' && apr_isdigit(expected[y + 1])); @@ -1518,10 +1515,12 @@ static int ap_proxy_strcmp_ematch(const char *str, const char *expected) } return -1; } - else if (expected[y] == '\\') { + else if (!str[x]) { + return -1; + } + else if (expected[y] == '\\' && !expected[++y]) { /* NUL is an invalid char! */ - if (!expected[++y]) - return -2; + return -2; } if (str[x] != expected[y]) return 1; diff --git a/server/util.c b/server/util.c index d302764e34..5ec8f8e6e0 100644 --- a/server/util.c +++ b/server/util.c @@ -190,8 +190,6 @@ AP_DECLARE(int) ap_strcmp_match(const char *str, const char *expected) int x, y; for (x = 0, y = 0; expected[y]; ++y, ++x) { - if ((!str[x]) && (expected[y] != '*')) - return -1; if (expected[y] == '*') { while (expected[++y] == '*'); if (!expected[y]) @@ -203,6 +201,8 @@ AP_DECLARE(int) ap_strcmp_match(const char *str, const char *expected) } return -1; } + else if (!str[x]) + return -1; else if ((expected[y] != '?') && (str[x] != expected[y])) return 1; } -- 2.50.1