mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
ext/gettext/gettext.c: handle NULLs from bindtextdomain()
According to POSIX, bindtextdomain() returns "the implementation- defined default directory pathname used by the gettext family of functions" when its second parameter is NULL (i.e. when you are querying the directory corresponding to some text domain and that directory has not yet been set). Its PHP counterpart is feeding that result direclty to RETURN_STRING, but this can go wrong in two ways: 1. If an error occurs, even POSIX-compliant implementations may return NULL. 2. At least one non-compliant implementation (musl) lacks a default directory and returns NULL whenever the domain has not yet been bound. In either of those cases, PHP segfaults on the NULL string. In this commit we check for the NULL, and RETURN_FALSE when it happens rather than crashing. This partially addresses GH #13696
This commit is contained in:
parent
53b69ba8cf
commit
0221ceeccd
1 changed files with 11 additions and 2 deletions
|
@ -167,7 +167,7 @@ PHP_FUNCTION(bindtextdomain)
|
|||
char *domain;
|
||||
size_t domain_len;
|
||||
zend_string *dir = NULL;
|
||||
char *retval, dir_name[MAXPATHLEN];
|
||||
char *retval, dir_name[MAXPATHLEN], *btd_result;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS!", &domain, &domain_len, &dir) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
|
@ -181,7 +181,16 @@ PHP_FUNCTION(bindtextdomain)
|
|||
}
|
||||
|
||||
if (dir == NULL) {
|
||||
RETURN_STRING(bindtextdomain(domain, NULL));
|
||||
btd_result = bindtextdomain(domain, NULL);
|
||||
if (btd_result == NULL) {
|
||||
/* POSIX-compliant implementations can return
|
||||
* NULL if an error occured. On musl you will
|
||||
* also get NULL if the domain is not yet
|
||||
* bound, because musl has no default directory
|
||||
* to return in that case. */
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_STRING(btd_result);
|
||||
}
|
||||
|
||||
if (ZSTR_LEN(dir) != 0 && !zend_string_equals_literal(dir, "0")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue