Skip to content

Commit 394fe12

Browse files
committed
ext/gettext/gettext.c: check errno after calling bindtextdomain()
Since musl's bindtextdomain() returns NULL when no directory has been explicitly bound yet (a relatively benign situation), we need to reset errno before the call and check it afterwards to differentiate between a real error like ENOMEM and the harmless not-yet-bound case.
1 parent e553c0d commit 394fe12

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ext/gettext/gettext.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#ifdef HAVE_LIBINTL
2424

25+
#include <errno.h>
2526
#include <stdio.h>
2627
#include <stdlib.h> /* secure_getenv() */
2728
#include <locale.h>
@@ -192,7 +193,15 @@ PHP_FUNCTION(bindtextdomain)
192193
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))
193194

194195
if (dir == NULL) {
196+
/* We need to reset errno because musl's bindtextdomain()
197+
* "fails" on one of the success paths and we need to
198+
* distinguish between a real disaster (e.g. ENOMEM)
199+
* and something harmless. */
200+
errno = 0;
195201
btd_result = bindtextdomain(ZSTR_VAL(domain), NULL);
202+
if (errno) {
203+
RETURN_FALSE;
204+
}
196205
if (btd_result == NULL) {
197206
/* It's not POSIX compliant, but musl returns
198207
* NULL rather than an implementation-defined

0 commit comments

Comments
 (0)