]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mqtt: Fix parser for string with more than 127 characters
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 28 Jun 2021 13:26:00 +0000 (15:26 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 28 Jun 2021 14:29:44 +0000 (16:29 +0200)
Parsing of too long strings (> 127 characters) was buggy because of a wrong
cast on the length bytes. To fix the bug, we rely on mqtt_read_2byte_int()
function. This way, the string length is properly decoded.

This patch should partely fix the issue #1310. It must be backported to 2.4.

reg-tests/converter/mqtt.vtc
src/mqtt.c

index 15d03ed7a27f356bdbde1d04cc5ac59ac7a6908e..59818246a73ee5a5daff051fb06c6e36e88de9f5 100644 (file)
@@ -4,8 +4,8 @@ varnishtest "mqtt converters Test"
 feature ignore_unknown_macro
 
 server s1 {
-    # MQTT 3.1.1 CONNECT packet (id: test_sub)
-    recv 22
+    # MQTT 3.1.1 CONNECT packet (id: test_subaaaaaa... [len = 200])
+    recv 215
     sendhex "20020000"
     close
 
@@ -114,7 +114,7 @@ haproxy h1 -conf {
 
 client c1_311_1 -connect ${h1_fe1_sock} {
     # Valid MQTT 3.1.1 CONNECT packet (id: test_sub)
-    sendhex "101400044d5154540402003c0008746573745f737562"
+    sendhex "10d40100044d5154540402003c00c8746573745f737562616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161"
     recv 4
     expect_close
 } -run
index 7679cbae6f56547939e8bd7719247c26bddde83b..8a6b6a0652f7d9a0c477435fa02638fa5f43c472 100644 (file)
@@ -288,15 +288,14 @@ static inline struct ist mqtt_read_varint(struct ist parser, uint32_t *i)
  */
 static inline struct ist mqtt_read_string(struct ist parser, struct ist *str)
 {
-       uint16_t len;
+       uint16_t len = 0;
 
        /* read and compute the string length */
        if (istlen(parser) <= 2)
                goto error;
 
-       len = ((uint16_t)*istptr(parser) << 8) + (uint16_t)*(istptr(parser) + 1);
-       parser = istadv(parser, 2);
-       if (istlen(parser) < len)
+       parser = mqtt_read_2byte_int(parser, &len);
+       if (!isttest(parser) || istlen(parser) < len)
                goto error;
 
        if (str) {