Skip to content

Commit a35fd15

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 a35fd15

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

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)