]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: pattern: pat_ref_set: fix UAF reported by coverity
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 12 Aug 2024 13:32:00 +0000 (15:32 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Tue, 13 Aug 2024 14:13:41 +0000 (16:13 +0200)
commit4f2493f3551f8c344485cccf075c3b15f9825181
tree9fcc953ba9f7debb8c2644fb7ac7d45706adc3ad
parent0982bfd9997d73bae1257da56413898f5f8d97fe
BUG/MINOR: pattern: pat_ref_set: fix UAF reported by coverity

memprintf() performs realloc and updates then the pointer to an output buffer,
where it has written the data. So free() is called on the previous buffer
address, if it was provided.

pat_ref_set_elt() uses memprintf() to write its error message as well as
pat_ref_set(). So, when we re-enter into the while loop the second time and
pat_ref_set_elt() has returned, the *err ptr (previous value of *merr) is
already freed by memprintf() from pat_ref_set_el().

'if (!found)' condition is false at this point, because we've found a node at
the first loop. So, the second memprintf(), in order to write error messages,
does again free(*err).

This should be backported in all stable versions.
src/pattern.c