Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Zend/tests/bug67368.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
Bug #67368 (Memory leak with immediately dereferenced array in class constant)
--INI--
report_memleaks=1
--FILE--
<?php
class FooBar {
Expand Down
1 change: 0 additions & 1 deletion Zend/tests/bug81104.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Bug #81104: Warning: "Failed to set memory limit to ... bytes" emitted after exit in debug
--INI--
memory_limit=5M
report_memleaks=0
--FILE--
<?php
#[AllowDynamicProperties]
Expand Down
2 changes: 0 additions & 2 deletions Zend/tests/exceptions/bug26698.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Bug #26698 (Thrown exceptions while evaluating argument to pass as parameter cra
--FILE--
<?php

ini_set("report_memleaks", 0); // the exception thrown in this test results in a memory leak, which is fine

class ObjectOne
{
function getNone()
Expand Down
25 changes: 25 additions & 0 deletions ext/calendar/calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ PHP_FUNCTION(cal_days_in_month)
RETURN_THROWS();
}

if (UNEXPECTED(month <= 0 || month > INT32_MAX - 1)) {
zend_argument_value_error(2, "must be between 1 and %d", INT32_MAX - 1);
RETURN_THROWS();
}

if (UNEXPECTED(year > INT32_MAX - 1)) {
zend_argument_value_error(3, "must be less than %d", INT32_MAX - 1);
RETURN_THROWS();
}

calendar = &cal_conversion_table[cal];

sdn_start = calendar->to_jd(year, month, 1);
Expand Down Expand Up @@ -242,6 +252,21 @@ PHP_FUNCTION(cal_to_jd)
RETURN_THROWS();
}

if (UNEXPECTED(month <= 0 || month > INT32_MAX - 1)) {
zend_argument_value_error(2, "must be between 1 and %d", INT32_MAX - 1);
RETURN_THROWS();
}

if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(day))) {
zend_argument_value_error(3, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}

if (UNEXPECTED(year > INT32_MAX - 1)) {
zend_argument_value_error(4, "must be less than %d", INT32_MAX - 1);
RETURN_THROWS();
}

RETURN_LONG(cal_conversion_table[cal].to_jd(year, month, day));
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_days_in_month_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
echo "{$ex->getMessage()}\n";
}
try{
cal_days_in_month(CAL_GREGORIAN,0, 2009);
cal_days_in_month(CAL_GREGORIAN,20, 2009);
} catch (ValueError $ex) {
echo "{$ex->getMessage()}\n";
}
Expand Down
61 changes: 61 additions & 0 deletions ext/calendar/tests/gh19371.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
GH-19371 (integer overflow in calendar.c)
--SKIPIF--
<?php if (PHP_INT_SIZE !== 8) die("skip only for 64-bit"); ?>
--EXTENSIONS--
calendar
--FILE--
<?php

try {
echo cal_days_in_month(CAL_GREGORIAN, 12, PHP_INT_MAX);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_days_in_month(CAL_GREGORIAN, PHP_INT_MIN, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_days_in_month(CAL_GREGORIAN, PHP_INT_MAX, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
echo cal_to_jd(CAL_GREGORIAN, PHP_INT_MIN, 1, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, PHP_INT_MAX, 1, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, PHP_INT_MIN, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, PHP_INT_MAX, 1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
echo cal_to_jd(CAL_GREGORIAN, 1, 1, PHP_INT_MAX);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
cal_days_in_month(): Argument #3 ($year) must be less than 2147483646
cal_days_in_month(): Argument #2 ($month) must be between 1 and 2147483646
cal_days_in_month(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #2 ($month) must be between 1 and 2147483646
cal_to_jd(): Argument #3 ($day) must be between -2147483648 and 2147483647
cal_to_jd(): Argument #3 ($day) must be between -2147483648 and 2147483647
cal_to_jd(): Argument #4 ($year) must be less than 2147483646
16 changes: 8 additions & 8 deletions ext/intl/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ if test "$PHP_INTL" != "no"; then
intl_convert.c
intl_error.c
listformatter/listformatter_class.c
msgformat/msgformat_attr.c
msgformat/msgformat_class.c
msgformat/msgformat_data.c
msgformat/msgformat_format.c
msgformat/msgformat_parse.c
msgformat/msgformat.c
normalizer/normalizer_class.c
normalizer/normalizer_normalize.c
php_intl.c
resourcebundle/resourcebundle_class.c
resourcebundle/resourcebundle_iterator.c
Expand Down Expand Up @@ -73,6 +65,14 @@ if test "$PHP_INTL" != "no"; then
calendar/calendar_class.cpp \
calendar/calendar_methods.cpp \
calendar/gregoriancalendar_methods.cpp \
msgformat/msgformat_attr.cpp \
msgformat/msgformat_class.cpp \
msgformat/msgformat_data.cpp \
msgformat/msgformat_format.cpp \
msgformat/msgformat_parse.cpp \
msgformat/msgformat.cpp \
normalizer/normalizer_class.cpp \
normalizer/normalizer_normalize.cpp \
breakiterator/breakiterator_class.cpp \
breakiterator/breakiterator_iterators.cpp \
breakiterator/breakiterator_methods.cpp \
Expand Down
16 changes: 8 additions & 8 deletions ext/intl/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ if (PHP_INTL != "no") {
locale_methods.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/msgformat", "\
msgformat.c \
msgformat_attr.c \
msgformat_class.c \
msgformat_data.c \
msgformat_format.c \
msgformat.cpp \
msgformat_attr.cpp \
msgformat_class.cpp \
msgformat_data.cpp \
msgformat_format.cpp \
msgformat_helpers.cpp \
msgformat_parse.c \
msgformat_parse.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/grapheme", "\
grapheme_string.c grapheme_util.c \
", "intl");
ADD_SOURCES(configure_module_dirname + "/normalizer", "\
normalizer_class.c \
normalizer_normalize.c \
normalizer_class.cpp \
normalizer_normalize.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
dateformat.c \
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/locale/locale_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ static int handleAppendResult( int result, smart_str* loc_name)
* }}} */
U_CFUNC PHP_FUNCTION(locale_compose)
{
smart_str loc_name_s = {0};
smart_str loc_name_s = {NULL, 0};
smart_str *loc_name = &loc_name_s;
zval* arr = NULL;
HashTable* hash_arr = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include <unicode/ustring.h>
#include <unicode/umsg.h>

extern "C" {
#include "php_intl.h"
#include "msgformat_class.h"
#include "msgformat_data.h"
#include "intl_convert.h"
}

/* {{{ */
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
Expand Down Expand Up @@ -99,7 +101,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* }}} */

/* {{{ Create formatter. */
PHP_FUNCTION( msgfmt_create )
U_CFUNC PHP_FUNCTION( msgfmt_create )
{
object_init_ex( return_value, MessageFormatter_ce_ptr );
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
Expand All @@ -110,7 +112,7 @@ PHP_FUNCTION( msgfmt_create )
/* }}} */

/* {{{ MessageFormatter object constructor. */
PHP_METHOD( MessageFormatter, __construct )
U_CFUNC PHP_METHOD( MessageFormatter, __construct )
{
const bool old_use_exception = INTL_G(use_exceptions);
const zend_long old_error_level = INTL_G(error_level);
Expand All @@ -127,7 +129,7 @@ PHP_METHOD( MessageFormatter, __construct )
/* }}} */

/* {{{ Get formatter's last error code. */
PHP_FUNCTION( msgfmt_get_error_code )
U_CFUNC PHP_FUNCTION( msgfmt_get_error_code )
{
zval* object = NULL;
MessageFormatter_object* mfo = NULL;
Expand All @@ -147,7 +149,7 @@ PHP_FUNCTION( msgfmt_get_error_code )
/* }}} */

/* {{{ Get text description for formatter's last error code. */
PHP_FUNCTION( msgfmt_get_error_message )
U_CFUNC PHP_FUNCTION( msgfmt_get_error_message )
{
zend_string* message = NULL;
zval* object = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
#include <config.h>
#endif

extern "C" {
#include "php_intl.h"
#include "msgformat_class.h"
#include "msgformat_data.h"
#include "intl_convert.h"
}

#include <unicode/ustring.h>

/* {{{ Get formatter pattern. */
PHP_FUNCTION( msgfmt_get_pattern )
U_CFUNC PHP_FUNCTION( msgfmt_get_pattern )
{
MSG_FORMAT_METHOD_INIT_VARS;

Expand All @@ -46,7 +48,7 @@ PHP_FUNCTION( msgfmt_get_pattern )
/* }}} */

/* {{{ Set formatter pattern. */
PHP_FUNCTION( msgfmt_set_pattern )
U_CFUNC PHP_FUNCTION( msgfmt_set_pattern )
{
char* value = NULL;
size_t value_len = 0;
Expand Down Expand Up @@ -105,7 +107,7 @@ PHP_FUNCTION( msgfmt_set_pattern )
/* }}} */

/* {{{ Get formatter locale. */
PHP_FUNCTION( msgfmt_get_locale )
U_CFUNC PHP_FUNCTION( msgfmt_get_locale )
{
char *loc;
MSG_FORMAT_METHOD_INIT_VARS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

#include <unicode/unum.h>

extern "C" {
#include "msgformat_class.h"
#include "php_intl.h"
#include "msgformat_data.h"
#include "msgformat_arginfo.h"
}

#include <zend_exceptions.h>

Expand All @@ -29,7 +31,7 @@ static zend_object_handlers MessageFormatter_handlers;
*/

/* {{{ MessageFormatter_objects_free */
void MessageFormatter_object_free( zend_object *object )
U_CFUNC void MessageFormatter_object_free( zend_object *object )
{
MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object);

Expand All @@ -40,11 +42,11 @@ void MessageFormatter_object_free( zend_object *object )
/* }}} */

/* {{{ MessageFormatter_object_create */
zend_object *MessageFormatter_object_create(zend_class_entry *ce)
U_CFUNC zend_object *MessageFormatter_object_create(zend_class_entry *ce)
{
MessageFormatter_object* intern;

intern = zend_object_alloc(sizeof(MessageFormatter_object), ce);
intern = reinterpret_cast<MessageFormatter_object *>(zend_object_alloc(sizeof(MessageFormatter_object), ce));
msgformat_data_init( &intern->mf_data );
zend_object_std_init( &intern->zo, ce );
object_properties_init(&intern->zo, ce);
Expand All @@ -54,7 +56,7 @@ zend_object *MessageFormatter_object_create(zend_class_entry *ce)
/* }}} */

/* {{{ MessageFormatter_object_clone */
zend_object *MessageFormatter_object_clone(zend_object *object)
U_CFUNC zend_object *MessageFormatter_object_clone(zend_object *object)
{
MessageFormatter_object *mfo = php_intl_messageformatter_fetch_object(object);
zend_object *new_obj = MessageFormatter_ce_ptr->create_object(object->ce);
Expand All @@ -66,7 +68,7 @@ zend_object *MessageFormatter_object_clone(zend_object *object)
/* clone formatter object */
if (MSG_FORMAT_OBJECT(mfo) != NULL) {
UErrorCode error = U_ZERO_ERROR;
MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &error);
MSG_FORMAT_OBJECT(new_mfo) = reinterpret_cast<UMessageFormat *>(umsg_clone(MSG_FORMAT_OBJECT(mfo), &error));

if (U_FAILURE(error)) {
zend_throw_error(NULL, "Failed to clone MessageFormatter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* {{{ void msgformat_data_init( msgformat_data* mf_data )
* Initialize internals of msgformat_data.
*/
void msgformat_data_init( msgformat_data* mf_data )
U_CFUNC void msgformat_data_init( msgformat_data* mf_data )
{
if( !mf_data )
return;
Expand All @@ -40,7 +40,7 @@ void msgformat_data_init( msgformat_data* mf_data )
/* {{{ void msgformat_data_free( msgformat_data* mf_data )
* Clean up memory allocated for msgformat_data
*/
void msgformat_data_free(msgformat_data* mf_data)
U_CFUNC void msgformat_data_free(msgformat_data* mf_data)
{
if (!mf_data)
return;
Expand Down Expand Up @@ -69,7 +69,7 @@ void msgformat_data_free(msgformat_data* mf_data)
*/
msgformat_data* msgformat_data_create( void )
{
msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) );
msgformat_data* mf_data = reinterpret_cast<msgformat_data *>(ecalloc( 1, sizeof(msgformat_data) ));

msgformat_data_init( mf_data );

Expand Down
Loading