]> granicus.if.org Git - php/commitdiff
Fixed bug #74385 Locale::parseLocale() broken with some arguments
authorAnatol Belski <ab@php.net>
Thu, 3 May 2018 14:34:33 +0000 (16:34 +0200)
committerAnatol Belski <ab@php.net>
Thu, 3 May 2018 14:34:33 +0000 (16:34 +0200)
Rely on the ICU's defined values for the max locale id length.

ext/intl/intl_data.h

index 74b7092fbb2eac94faa9487fa8941f86ccdba038..898a174a22a8d86309185c74a3c2a3ecbbcf114b 100644 (file)
@@ -103,19 +103,23 @@ typedef struct _intl_data {
        RETVAL_NEW_STR(u8str);                                                                                                                                          \
 }
 
-#define INTL_MAX_LOCALE_LEN 80
+#define INTL_MAX_LOCALE_LEN (ULOC_FULLNAME_CAPACITY-1)
 
 #define INTL_CHECK_LOCALE_LEN(locale_len)                                                                                              \
        if((locale_len) > INTL_MAX_LOCALE_LEN) {                                                                                        \
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,                                                                 \
-               "Locale string too long, should be no longer than 80 characters", 0 );                  \
+               char *_msg; \
+               spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN);                      \
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1);                                                               \
+               efree(_msg); \
                RETURN_NULL();                                                                                                                                  \
        }
 
 #define INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len)                                                                   \
        if((locale_len) > INTL_MAX_LOCALE_LEN) {                                                                                        \
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,                                                                 \
-               "Locale string too long, should be no longer than 80 characters", 0 );                  \
+               char *_msg; \
+               spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN);                      \
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1);                                                               \
+               efree(_msg); \
                return FAILURE;                                                                                                                                 \
        }