Skip to content

Commit b7039f2

Browse files
committed
ext/gettext: return false from textdomain() and bindtextdomain() on NULL
Both functions can return NULL on libintl-internal allocation failure. The PHP wrappers passed the result directly to RETURN_STRING, which calls strlen(NULL) and segfaults. Mirrors 0221cee, which closed the same gap for bindtextdomain($domain, NULL). textdomain()'s return type widens from string to string|false.
1 parent 171b722 commit b7039f2

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

Zend/Optimizer/zend_func_infos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static const func_info_t func_infos[] = {
145145
F1("imageaffinematrixget", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_DOUBLE|MAY_BE_FALSE),
146146
F1("imageaffinematrixconcat", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_DOUBLE|MAY_BE_FALSE),
147147
F1("imageresolution", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_TRUE),
148-
F1("textdomain", MAY_BE_STRING),
148+
F1("textdomain", MAY_BE_STRING|MAY_BE_FALSE),
149149
F1("gettext", MAY_BE_STRING),
150150
F1("dgettext", MAY_BE_STRING),
151151
F1("dcgettext", MAY_BE_STRING),

ext/gettext/gettext.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ PHP_FUNCTION(textdomain)
9999
}
100100

101101
retval = textdomain(domain_name);
102+
if (retval == NULL) {
103+
RETURN_FALSE;
104+
}
102105

103106
RETURN_STRING(retval);
104107
}
@@ -212,6 +215,9 @@ PHP_FUNCTION(bindtextdomain)
212215
}
213216

214217
retval = bindtextdomain(ZSTR_VAL(domain), dir_name);
218+
if (retval == NULL) {
219+
RETURN_FALSE;
220+
}
215221

216222
RETURN_STRING(retval);
217223
}

ext/gettext/gettext.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/** @generate-class-entries */
44

55
/** @refcount 1 */
6-
function textdomain(?string $domain = null): string {}
6+
function textdomain(?string $domain = null): string|false {}
77

88
/** @refcount 1 */
99
function gettext(string $message): string {}

ext/gettext/gettext_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)