Commit 894f215ba3a for php.net
commit 894f215ba3ad63574ec0f4c9729a5295f7ea787d
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Sat Sep 19 19:19:41 2026 -0400
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.
diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c
index 172ae76d387..c992dfc40e6 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);
}
/* }}} */