com php-src: Fixed bug #68893 Stackoverflow in datefmt_create : ext/intl/dateformat/dateformat_create.cpp ext/intl/ tests/dateformat_bug68893.phpt

From: Date: Fri, 08 Apr 2016 10:31:19 +0000
Subject: com php-src: Fixed bug #68893 Stackoverflow in datefmt_create : ext/intl/dateformat/dateformat_create.cpp ext/intl/ tests/dateformat_bug68893.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-91662@lists.php.net to get a copy of this message
Commit: 1541a55a4f9207c346a805c2b8d090f16d07f841 Author: Anatol Belski <ab@php.net> Fri, 8 Apr 2016 12:29:40 +0200 Parents: f7600e17cb8eb6c5dad8709ac1f4c76f0f28f207 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1541a55a4f9207c346a805c2b8d090f16d07f841 Log: Fixed bug #68893 Stackoverflow in datefmt_create Bugs: https://bugs.php.net/68893 Changed paths: M ext/intl/dateformat/dateformat_create.cpp A ext/intl/tests/dateformat_bug68893.phpt Diff: diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index e90ad74..8705d4b 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -36,6 +36,13 @@ extern "C" { #include "dateformat_helpers.h" #include "zend_exceptions.h" +#define INTL_UDATE_FMT_OK(i) \ + (UDAT_FULL == (i) || UDAT_LONG == (i) || \ + UDAT_MEDIUM == (i) || UDAT_SHORT == (i) || \ + UDAT_RELATIVE == (i) || UDAT_FULL_RELATIVE == (i) || \ + UDAT_LONG_RELATIVE == (i) || UDAT_MEDIUM_RELATIVE == (i) || \ + UDAT_SHORT_RELATIVE == (i) || UDAT_NONE == (i) || \ + UDAT_PATTERN == (i)) /* {{{ */ static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) @@ -72,12 +79,6 @@ static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) return FAILURE; } - INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); - if (locale_len == 0) { - locale_str = intl_locale_get_default(); - } - locale = Locale::createFromName(locale_str); - DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { @@ -86,6 +87,21 @@ static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) return FAILURE; } + if (!INTL_UDATE_FMT_OK(date_type)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid date format style", 0); + return FAILURE; + } + if (!INTL_UDATE_FMT_OK(time_type)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid time format style", 0); + return FAILURE; + } + + INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); + if (locale_len == 0) { + locale_str = intl_locale_get_default(); + } + locale = Locale::createFromName(locale_str); + /* process calendar */ if (datefmt_process_calendar_arg(calendar_zv, locale, "datefmt_create", INTL_DATA_ERROR_P(dfo), calendar, calendar_type, diff --git a/ext/intl/tests/dateformat_bug68893.phpt b/ext/intl/tests/dateformat_bug68893.phpt new file mode 100644 index 0000000...b3faf54 --- /dev/null +++ b/ext/intl/tests/dateformat_bug68893.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #68893 Stackoverflow in datefmt_create +--SKIPIF-- +<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> +--FILE-- +<?php + +$f = datefmt_create("en_us", -10000000, 1); +var_dump($f, intl_get_error_message()); + +$f = datefmt_create("en_us", 1, -10000000); +var_dump($f, intl_get_error_message()); + +?> +--EXPECT-- +NULL +string(67) "datefmt_create: invalid date format style: U_ILLEGAL_ARGUMENT_ERROR" +NULL +string(67) "datefmt_create: invalid time format style: U_ILLEGAL_ARGUMENT_ERROR"

« previous php.cvs (#91662) next »