Hi guys,

Each time we generate a new dynamic cookie, we compare it with other
servers' cookies, to make sure we didn't generate that one, as unlikely as
it is. The existing code attempts at comparing it for every server of every
proxy (and fails, because it bogusly checks against the server list of
the first proxy at each iteration, making it a total waste of cycles), but
we only have to worry about the current proxy, so that's what the attached
patch does.
Willy, I think it is mostly safe and you can apply it.

Cheers,

Olivier
>From 3fe44f06b4ba964a71582c4460400b489f7dcf72 Mon Sep 17 00:00:00 2001
From: Olivier Houchard <[email protected]>
Date: Tue, 4 Apr 2017 22:10:36 +0200
Subject: [PATCH] MINOR server: Restrict dynamic cookie check to the same
 proxy.

Each time we generate a dynamic cookie, we try to make sure the same
cookie hasn't been generated for another server, it's very unlikely, but
it may happen.
We only have to check that for the servers in the same proxy, no, need to
check in others, plus the code was buggy and would always check in the
first proxy of the proxy list.
---
 src/server.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/server.c b/src/server.c
index 23343d86..6070de93 100644
--- a/src/server.c
+++ b/src/server.c
@@ -135,18 +135,17 @@ void srv_set_dyncookie(struct server *s)
         * Check that we did not get a hash collision.
         * Unlikely, but it can happen.
         */
-       for (p = proxy; p != NULL; p = p->next)
-               for (tmpserv = proxy->srv; tmpserv != NULL;
-                   tmpserv = tmpserv->next) {
-                       if (tmpserv == s)
-                               continue;
-                       if (tmpserv->cookie &&
-                           strcmp(tmpserv->cookie, s->cookie) == 0) {
-                               Warning("We generated two equal cookies for two 
different servers.\n"
-                                   "Please change the secret key for '%s'.\n",
-                                   s->proxy->id);
-                       }
+       for (tmpserv = p->srv; tmpserv != NULL;
+           tmpserv = tmpserv->next) {
+               if (tmpserv == s)
+                       continue;
+               if (tmpserv->cookie &&
+                   strcmp(tmpserv->cookie, s->cookie) == 0) {
+                       Warning("We generated two equal cookies for two 
different servers.\n"
+                           "Please change the secret key for '%s'.\n",
+                           s->proxy->id);
                }
+       }
 }
 
 /*
-- 
2.11.0

Reply via email to