Commit 6f1c108
committed
ext/gettext/gettext.c: fudge bindtextdomain() return value on musl
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). But musl does not do this: when no
directory has been set, it consults an environment variable (that
itself may be unset), and there is no default:
if (!libc.secure) path = getenv("MUSL_LOCPATH");
/* FIXME: add a default path? */
Worse, the musl bindtextdomain(..., NULL) query always returns NULL,
even when MUSL_LOCPATH is set. This is segfaulting bindtextdomain() in
PHP because it tries to RETURN_STRING on the NULL pointer that the C
function returns.
To work around this, we check for a NULL return from the C function,
and then try to return the value of MUSL_LOCPATH. (This still isn't
perfect, because MUSL_LOCPATH can contain multiple paths, but at least
it's a string.) If MUSL_LOCPATH is unset, we RETURN_FALSE to indicate
failure (there's really no default) rather than segfaulting.
This partially addresses GH #136961 parent fa8c6a5 commit 6f1c108
1 file changed
+24
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
183 | | - | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
195 | 217 | | |
196 | 218 | | |
197 | 219 | | |
| |||
0 commit comments