[php-src] PR #25897: Fix NULL pointer dereference in locale_parse() and locale_get_all_variants()
| From: | hohphu8 | Date: | Sun, 29 Nov 2026 12:03:37 +0000 |
| Subject: | [php-src] PR #25897: Fix NULL pointer dereference in locale_parse() and locale_get_all_variants() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41192@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25897
Author: hohphu8
In
ext/intl/locale/locale_methods.c, both add_array_entry() (used by
Locale::parseLocale() / locale_parse()) and
locale_get_all_variants() call php_strtok_r() on private/variant subtags
without checking for a NULL return before passing token to
add_assoc_string() or strlen(). Passing a locale string whose private or
variant portion consists only of delimiters (e.g.,
Locale::parseLocale('en-x--'),
Locale::parseLocale('en_US___'), or
Locale::getAllVariants('en_US___')) causes a NULL pointer dereference
(SIGSEGV).
Guard the first php_strtok_r() call in both functions with if (token)
before allocating/adding entries or calling strlen().
Added a regression test covering delimiter-only private and variant subtags for both
Locale::parseLocale() and Locale::getAllVariants().
Note: AI-assisted code audit; manually verified and reproduced locally.