]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: backend: fix URI hash when a query string is present
authorWilly Tarreau <w@1wt.eu>
Fri, 17 Oct 2014 10:11:50 +0000 (12:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Oct 2014 10:11:50 +0000 (12:11 +0200)
Commit 98634f0 ("MEDIUM: backend: Enhance hash-type directive with an
algorithm options") cleaned up the hashing code by using a centralized
function. A bug appeared in get_server_uh() which is the URI hashing
function. Prior to the patch, the function would stop hashing on the
question mark, or on the trailing slash of a maximum directory count.
Consecutive to the patch, this last character is included into the
hash computation. This means that :

    GET /0
    GET /0?

Are not hashed similarly. The following configuration reproduces it :

    mode http
    balance uri
    server s1 0.0.0.0:1234 redir /s1
    server s2 0.0.0.0:1234 redir /s2

Many thanks to Vedran Furac for reporting this issue. The fix must
be backported to 1.5.

src/backend.c

index a96b767323d55bd16ea50a2ab9a2718138158a40..6fe03f95176342ff8c72b9854379b3985763bb74 100644 (file)
@@ -200,7 +200,7 @@ struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
 
        start = end = uri;
        while (uri_len--) {
-               c = *end++;
+               c = *end;
                if (c == '/') {
                        slashes++;
                        if (slashes == px->uri_dirs_depth1) /* depth+1 */
@@ -208,6 +208,7 @@ struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
                }
                else if (c == '?' && !px->uri_whole)
                        break;
+               end++;
        }
 
        hash = gen_hash(px, start, (end - start));