]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sample: fix the json converter's endian-sensitivity
authorWilly Tarreau <w@1wt.eu>
Tue, 25 Feb 2020 07:37:37 +0000 (08:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 25 Feb 2020 07:47:45 +0000 (08:47 +0100)
About every time there's a pointer cast in the code, there's a hidden
bug, and this one was no exception, as it passes the first octet of the
native representation of an integer as a single-character string, which
obviously only works on little endian machines. On big-endian machines,
something as simple as "str(foo),json" only returns zeroes.

This bug was introduced with the JSON converter in 1.6-dev1 by commit
317e1c4f1e ("MINOR: sample: add "json" converter"), the fix may be
backported to all stable branches.

src/sample.c

index eb903ec6d31b5ed187b7857bcfd1ee95cd45260a..0fb5f9aa799f89c34c701d8efc96a4ddc30b3529 100644 (file)
@@ -2058,7 +2058,8 @@ static int sample_conv_json(const struct arg *arg_p, struct sample *smp, void *p
                }
                else {
                        len = 1;
-                       str = (char *)&c;
+                       _str[0] = c;
+                       str = _str;
                }
 
                /* Check length */