Merge branch 'PHP-7.0'

* PHP-7.0:
  Fixed bug #68893 Stackoverflow in datefmt_create
  Added missing newline.
  Changed to check for error with the new function that returns null if error is set
  Added function to check error and return null if error is set.
  Added tests for bug 70451 and 70452
This commit is contained in:
Anatol Belski 2016-04-08 12:32:27 +02:00
commit de2da3bf02
6 changed files with 89 additions and 11 deletions

View File

@ -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,

View File

@ -45,7 +45,7 @@ typedef struct _intl_data {
obj = Z_##oclass##_P( object ); \
intl_error_reset( INTL_DATA_ERROR_P(obj) ); \
/* Check status by error code, if error - exit */
/* Check status by error code, if error return false */
#define INTL_CHECK_STATUS(err, msg) \
intl_error_set_code( NULL, (err) ); \
if( U_FAILURE((err)) ) \
@ -54,6 +54,16 @@ typedef struct _intl_data {
RETURN_FALSE; \
}
/* Check status by error code, if error return null */
#define INTL_CHECK_STATUS_OR_NULL(err, msg) \
intl_error_set_code( NULL, (err) ); \
if( U_FAILURE((err)) ) \
{ \
intl_error_set_custom_msg( NULL, msg, 0 ); \
RETURN_NULL(); \
}
/* Check status in object, if error return false */
#define INTL_METHOD_CHECK_STATUS(obj, msg) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \

View File

@ -0,0 +1,12 @@
--TEST--
Bug #70451 IntlChar::charFromName() not consistent with C library or HHVM
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--FILE--
<?php
var_dump(IntlChar::charFromName("RECYCLING SYMBOL FOR TYPE-1 PLASTICS"));
var_dump(IntlChar::charFromName("sdfasdfasdfasdf"));
?>
--EXPECT--
int(9843)
NULL

View File

@ -0,0 +1,21 @@
--TEST--
Bug #70452 string IntlChar::charName() can sometimes return bool(false)
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--FILE--
<?php
// Rely on the default value for the second parameter
var_dump(IntlChar::charName("A"));
// Provide a valid option for the second parameter
var_dump(IntlChar::charName("A", IntlChar::UNICODE_CHAR_NAME));
// Another valid option, but with no corresponding name for that given option
// This properly returns an empty string, as expected
var_dump(IntlChar::charName("A", IntlChar::UNICODE_10_CHAR_NAME));
// Provide an invalid value for the second parameter
var_dump(IntlChar::charName("A", 12345));
?>
--EXPECT--
string(22) "LATIN CAPITAL LETTER A"
string(22) "LATIN CAPITAL LETTER A"
string(0) ""
NULL

View File

@ -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"

View File

@ -241,7 +241,7 @@ IC_METHOD(charName) {
if ((zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &zcp, &nameChoice) == FAILURE) ||
(convert_cp(&cp, zcp) == FAILURE)) {
return;
RETURN_NULL();
}
buffer_len = u_charName(cp, (UCharNameChoice)nameChoice, NULL, 0, &error);
@ -250,7 +250,7 @@ IC_METHOD(charName) {
buffer_len = u_charName(cp, (UCharNameChoice)nameChoice, ZSTR_VAL(buffer), ZSTR_LEN(buffer) + 1, &error);
if (U_FAILURE(error)) {
zend_string_free(buffer);
INTL_CHECK_STATUS(error, "Failure getting character name");
INTL_CHECK_STATUS_OR_NULL(error, "Failure getting character name");
}
RETURN_NEW_STR(buffer);
}
@ -269,11 +269,11 @@ IC_METHOD(charFromName) {
UErrorCode error = U_ZERO_ERROR;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &name, &name_len, &nameChoice) == FAILURE) {
return;
RETURN_NULL();
}
ret = u_charFromName((UCharNameChoice)nameChoice, name, &error);
INTL_CHECK_STATUS(error, NULL);
INTL_CHECK_STATUS_OR_NULL(error, NULL);
RETURN_LONG(ret);
}
/* }}} */