]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-spop: match the AGENT-HELLO and AGENT-DISCONNECT keys exactly
authorMartin Mirchev <mirchevmartin2203@gmail.com>
Wed, 18 Nov 2026 12:34:24 +0000 (20:34 +0800)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2026 11:36:58 +0000 (12:36 +0100)
The K/V keys of the AGENT-HELLO and AGENT-DISCONNECT frames are compared
with "sz >= strlen(KEY) && !memcmp(str, KEY, strlen(KEY))", which is a
prefix match: an agent sending "max-frame-size-bogus" (or "versionX",
"capabilitiesX", "status-codeX") has the item treated as the mandatory
one. With an invalid value under "max-frame-size-bogus", haproxy closes the
connection with "max-frame-size too big or too small", exactly as for the
real key, while a key sharing no prefix is ignored as it should be.

Compare the whole key instead. The commented-out "message" check is
updated the same way.

This should be backported to all versions with mux-spop (3.1+).

src/mux_spop.c

index 06daaa7b925a68868314447ccb639397594c1240..daf5ace274419da89c4be8ca0006ed52a90ad25a 100644 (file)
@@ -1689,7 +1689,7 @@ static int spop_conn_handle_hello(struct spop_conn *spop_conn)
                }
 
                /* Check "version" K/V item */
-               if (sz >= strlen(SPOP_VERSION_KEY) && !memcmp(str, SPOP_VERSION_KEY, strlen(SPOP_VERSION_KEY))) {
+               if (sz == strlen(SPOP_VERSION_KEY) && !memcmp(str, SPOP_VERSION_KEY, sz)) {
                        int type = *p++;
 
                        /* The value must be a string */
@@ -1713,7 +1713,7 @@ static int spop_conn_handle_hello(struct spop_conn *spop_conn)
                        }
                }
                /* Check "max-frame-size" K/V item */
-               else if (sz >= strlen(SPOP_MAX_FRAME_SIZE_KEY) && !memcmp(str, SPOP_MAX_FRAME_SIZE_KEY, SPOP_SLEN(SPOP_MAX_FRAME_SIZE_KEY))) {
+               else if (sz == strlen(SPOP_MAX_FRAME_SIZE_KEY) && !memcmp(str, SPOP_MAX_FRAME_SIZE_KEY, sz)) {
                        int type = *p++;
 
                        /* The value must be integer */
@@ -1735,7 +1735,7 @@ static int spop_conn_handle_hello(struct spop_conn *spop_conn)
                        max_frame_size = sz;
                }
                /* Check "capabilities" K/V item */
-               else if (sz >= strlen(SPOP_CAPABILITIES_KEY) && !memcmp(str, SPOP_CAPABILITIES_KEY, SPOP_SLEN(SPOP_CAPABILITIES_KEY))) {
+               else if (sz == strlen(SPOP_CAPABILITIES_KEY) && !memcmp(str, SPOP_CAPABILITIES_KEY, sz)) {
                        int type = *p++;
 
                        /* The value must be a string */
@@ -1854,7 +1854,7 @@ static int spop_conn_handle_disconnect(struct spop_conn *spop_conn)
                }
 
                 /* Check "status-code" K/V item */
-                if (sz >= strlen(SPOP_STATUS_CODE_KEY) && !memcmp(str, SPOP_STATUS_CODE_KEY, strlen(SPOP_STATUS_CODE_KEY))) {
+                if (sz == strlen(SPOP_STATUS_CODE_KEY) && !memcmp(str, SPOP_STATUS_CODE_KEY, sz)) {
                         int type = *p++;
 
                         /* The value must be an integer */
@@ -1873,7 +1873,7 @@ static int spop_conn_handle_disconnect(struct spop_conn *spop_conn)
                 }
                // TODO: for now skip the reason
                 /* /\* Check "message" K/V item *\/ */
-                /* else if (sz >= strlen(SPOP_MSG_KEY) && !memcmp(str, SPOP_MSG_KEY, strlen(SPOP_MSG_KEY))) { */
+                /* else if (sz == strlen(SPOP_MSG_KEY) && !memcmp(str, SPOP_MSG_KEY, sz)) { */
                 /*         int type = *p++; */
 
                 /*         /\* The value must be a string *\/ */