[php-src] PR #17656: Fix GH-17650: realloc with size 0 in user_filters.c
| From: | nielsdos | Date: | Fri, 31 Jan 2025 19:11:16 +0000 |
| Subject: | [php-src] PR #17656: Fix GH-17650: realloc with size 0 in user_filters.c | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-30613@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/17656
Author: nielsdos
If the returned buffer string is of length 0, then a realloc can happen with length 0. However, the
behaviour is implementation-defined. From 7.20.3.1 of C11 spec:
> If the size of the space requested is zero, the behavior is
> implementation-defined: either a null pointer is returned,
> or the behavior is as if the size were some nonzero value,
> except that the returned pointer shall not be used to access an object
This is problematic for the test case on my system as it returns NULL, causing a memleak and later
using it in memcpy causing UB. The bucket code is not prepared to handle a NULL pointer. To solve
this, we use MAX to clamp the size to 1 at the least.