Skip to content

Commit e975c27

Browse files
committed
Fix GH-17400: bindtextdomain segfault with UTF-16 domain value.
The provided domain could be a non ascii value even if not supposed to, in the error reported case was of 4 code points long but domain is "empty" leading to a NULL return. It worked up to 8.3 "by accident" before the zend_string conversion and check prior for emptiness. close GH-17402
1 parent 38365a4 commit e975c27

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
. Added support for reading GIFs without colormap to bundled libgd. (Andrew
2626
Burley, cmb)
2727

28+
- Gettext:
29+
. Fixed bug GH-17400 (bindtextdomain SEGV on invalid domain).
30+
(David Carlier)
31+
2832
- Intl:
2933
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
3034

ext/gettext/gettext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ PHP_FUNCTION(bindtextdomain)
183183
char *retval, dir_name[MAXPATHLEN], *btd_result;
184184

185185
ZEND_PARSE_PARAMETERS_START(1, 2)
186-
Z_PARAM_STR(domain)
186+
Z_PARAM_PATH_STR(domain)
187187
Z_PARAM_OPTIONAL
188-
Z_PARAM_STR_OR_NULL(dir)
188+
Z_PARAM_PATH_STR_OR_NULL(dir)
189189
ZEND_PARSE_PARAMETERS_END();
190190

191191
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))

ext/gettext/tests/gh17400.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-17400 bindtextdomain segfaults with invalid domain/domain with null bytes.
3+
--EXTENSIONS--
4+
gettext
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$utf16_first_le = pack("H*", "00d800dc");
10+
$utf16le_char_bad = pack("H*", "00dc00dc");
11+
12+
try {
13+
bindtextdomain($utf16le_char_bad,$utf16_first_le);
14+
} catch (\ValueError $e) {
15+
echo $e->getMessage();
16+
}
17+
?>
18+
--EXPECT--
19+
bindtextdomain(): Argument #1 ($domain) must not contain any null bytes

0 commit comments

Comments
 (0)