From ee250471443c39aeca193b349b81c78ae48e3327 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 27 Apr 2026 08:26:32 -0400 Subject: [PATCH] ext/gettext: throw on libintl NULL return in textdomain/bindtextdomain 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. --- ext/gettext/gettext.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c index 27f0dfa26da7..4c08b9dbbab3 100644 --- a/ext/gettext/gettext.c +++ b/ext/gettext/gettext.c @@ -100,6 +100,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); } /* }}} */ @@ -213,6 +218,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); } /* }}} */