[php-src] master: ext/gettext: throw on libintl NULL return in textdomain/bindtextdomain (#21882)

From: Date: Sat, 19 Sep 2026 23:19:44 +0000
Subject: [php-src] master: ext/gettext: throw on libintl NULL return in textdomain/bindtextdomain (#21882)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141299@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Committer: GitHub (web-flow) Pusher: iliaal Date: 2026-09-19T19:19:41-04:00 Commit: https://github.com/php/php-src/commit/894f215ba3ad63574ec0f4c9729a5295f7ea787d Raw diff: https://github.com/php/php-src/commit/894f215ba3ad63574ec0f4c9729a5295f7ea787d.diff ext/gettext: throw on libintl NULL return in textdomain/bindtextdomain (#21882) Both functions can return NULL on libintl-internal allocation failure, which RETURN_STRING then fed to strlen(NULL) and crashed. Throw an Error in that case instead, leaving the existing string return type intact (no static-analysis fallout from a widened signature). The dir==NULL query path of bindtextdomain keeps its RETURN_FALSE because musl returns NULL there to signal an unbound domain, which is not an error condition. Changed paths: M ext/gettext/gettext.c Diff: diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c index 172ae76d3876..c992dfc40e69 100644 --- a/ext/gettext/gettext.c +++ b/ext/gettext/gettext.c @@ -98,6 +98,11 @@ PHP_FUNCTION(textdomain) retval = textdomain(domain_name); + if (UNEXPECTED(retval == NULL)) { + zend_throw_error(NULL, "Could not set text domain"); + RETURN_THROWS(); + } + RETURN_STRING(retval); } /* }}} */ @@ -211,6 +216,11 @@ PHP_FUNCTION(bindtextdomain) retval = bindtextdomain(ZSTR_VAL(domain), dir_name); + if (UNEXPECTED(retval == NULL)) { + zend_throw_error(NULL, "Could not bind text domain"); + RETURN_THROWS(); + } + RETURN_STRING(retval); } /* }}} */

« previous php.cvs (#141299) next »