File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -368,6 +368,24 @@ if test "$ac_cv_strptime_decl_fails" = "yes"; then
368
368
AC_DEFINE ( [ HAVE_STRPTIME_DECL_FAILS] , 1 , [ whether strptime() declaration fails] )
369
369
fi
370
370
371
+ dnl musl has a badly broken setlocale() implementation that always reports success.
372
+ AC_CACHE_CHECK ( [ whether setlocale() is broken] , ac_cv_setlocale_broken , [
373
+ AC_RUN_IFELSE ( [ AC_LANG_SOURCE ( [ [
374
+ #include <locale.h>
375
+ int main() {
376
+ return setlocale(LC_CTYPE, "This locale certainly does not exist") == NULL;
377
+ }
378
+ ] ] ) ] ,[
379
+ ac_cv_setlocale_broken=yes
380
+ ] ,[
381
+ ac_cv_setlocale_broken=no
382
+ ] ,[
383
+ ac_cv_setlocale_broken=no
384
+ ] ) ] )
385
+ if test "$ac_cv_setlocale_broken" = "yes"; then
386
+ AC_DEFINE ( [ HAVE_BROKEN_SETLOCALE] , 1 , [ whether setlocale() is broken] )
387
+ fi
388
+
371
389
dnl
372
390
dnl Check for arc4random on BSD systems
373
391
dnl
Original file line number Diff line number Diff line change @@ -4662,6 +4662,15 @@ PHP_FUNCTION(setlocale)
4662
4662
4663
4663
# ifndef PHP_WIN32
4664
4664
retval = php_my_setlocale (cat , loc ? ZSTR_VAL (loc ) : NULL );
4665
+ # if HAVE_BROKEN_SETLOCALE
4666
+ /* musl libc always reports success for setlocale().
4667
+ * Manually whitelist the allowed locales "", "C" and "C.UTF-8" instead. */
4668
+ if (retval && loc && ZSTR_LEN (loc ) != 0
4669
+ && !zend_string_equals_literal (loc , "C" )
4670
+ && !zend_string_equals_literal (loc , "C.UTF-8" )) {
4671
+ retval = NULL ;
4672
+ }
4673
+ # endif
4665
4674
# else
4666
4675
if (loc ) {
4667
4676
/* BC: don't try /^[a-z]{2}_[A-Z]{2}($|\..*)/ except for /^u[ks]_U[KS]$/ */
You can’t perform that action at this time.
0 commit comments