BUG/MINOR: jwt: fix jwt_verify crash on 32-bit archs
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Jan 2024 09:31:05 +0000 (10:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 31 Jan 2024 14:44:56 +0000 (15:44 +0100)
commit79ab2bc2a498c76b7fe43fe37d6dabd827f1ca50
treecdd9f9e9b0db7677c9e4c9e92c9d7664f5274d6c
parent5ed535046cdc83ecd4dedec4bda95f2fe268ebd9
BUG/MINOR: jwt: fix jwt_verify crash on 32-bit archs

The jwt_verify converter was added in 2.5 with commit 130e142ee2
("MEDIUM: jwt: Add jwt_verify converter to verify JWT integrity"). It
takes a string on input and returns an integer. It turns out that by
presetting the return value to zero before processing contents, while
the sample data is a union, it overwrites the beginning of the buffer
struct passed on input. On a 64-bit arch it's not an issue because it's
where the allocated size is stored and it's not used in the operation,
which explains why the regtest works. But on 32-bit, both the size and
the pointer are overwritten, causing a NULL pointer to be passed to
jwt_tokenize() which is not designed to support this, hence crashes.

Let's just use a temporary variable to hold the result and move the
output sample initialization to the end of the function.

This should be backported as far as 2.5.

(cherry picked from commit e41638af33d76660220ce2e3ed613e8a24fb6e55)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/sample.c