Skip to content

Commit 894f215

Browse files
authored
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.
1 parent 64760a1 commit 894f215

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

ext/gettext/gettext.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ PHP_FUNCTION(textdomain)
9898

9999
retval = textdomain(domain_name);
100100

101+
if (UNEXPECTED(retval == NULL)) {
102+
zend_throw_error(NULL, "Could not set text domain");
103+
RETURN_THROWS();
104+
}
105+
101106
RETURN_STRING(retval);
102107
}
103108
/* }}} */
@@ -211,6 +216,11 @@ PHP_FUNCTION(bindtextdomain)
211216

212217
retval = bindtextdomain(ZSTR_VAL(domain), dir_name);
213218

219+
if (UNEXPECTED(retval == NULL)) {
220+
zend_throw_error(NULL, "Could not bind text domain");
221+
RETURN_THROWS();
222+
}
223+
214224
RETURN_STRING(retval);
215225
}
216226
/* }}} */

0 commit comments

Comments
 (0)