BUG/MINOR: pattern: Do not pass len = 0 to calloc()
authorTim Duesterhus <tim@bastelstu.be>
Tue, 17 Mar 2020 20:08:24 +0000 (21:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Mar 2020 10:30:57 +0000 (12:30 +0200)
commit87fc6517dcbc7e967c879cbd1e3af2b64df02123
treed8b21753d1e5fbfd4005111dbc97446141862eb1
parentaf7f63f7df98c72f749acdff9682aa0872de7537
BUG/MINOR: pattern: Do not pass len = 0 to calloc()

The behavior of calloc() when being passed `0` as `nelem` is implementation
defined. It may return a NULL pointer.

Avoid this issue by checking before allocating. While doing so adjust the local
integer variables that are used to refer to memory offsets to `size_t`.

This issue was introced in commit f91ac19299fe216a793ba6550dca06b688b31549. This
patch should be backported together with that commit.

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