From 1c19146f464017a28779446ee0972d1956809d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Wed, 23 May 2012 13:35:11 +0200 Subject: [PATCH 1/3] Updated NEWS w.r.t to ext/intl changes --- NEWS | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 7542724e5d3..169366d8740 100644 --- a/NEWS +++ b/NEWS @@ -6,11 +6,19 @@ PHP NEWS - FPM . Fixed bug #61045 (fpm don't send error log to fastcgi clients). (fat) - . Fixed bug #61835 (php-fpm is not allowed to run as root). (fat) + . Fixed bug #61835 (php-fpm is not allowed to run as root). (fat) . Fixed bug #61295 (php-fpm should not fail with commented 'user' for non-root start). (fat) . Fixed bug #61026 (FPM pools can listen on the same address). (fat) +- Intl + . Fixed bug #62082 (grapheme_extract() memory leaks). (Gustavo) + . Fixed bug #62082 (Memory corruption in internal get_icu_disp_value_src_php + function). (Gustavo) + . Fixed bug #62081 (IntlDateFormatter constructor leaks memory when called + twice). (Gustavo) + . Fixed bug #62070 (Collator::getSortKey() returns garbage). (Gustavo) + - XML Writer: . Fixed bug #62064 (memory leak in the XML Writer module). (jean-pierre dot lozi at lip6 dot fr) From c449bf144373bb8ba1453f8c44801d2738c09d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Wed, 23 May 2012 13:42:24 +0200 Subject: [PATCH 2/3] Fixed bug number in NEWS --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 169366d8740..900dd5c5e98 100644 --- a/NEWS +++ b/NEWS @@ -12,7 +12,7 @@ PHP NEWS . Fixed bug #61026 (FPM pools can listen on the same address). (fat) - Intl - . Fixed bug #62082 (grapheme_extract() memory leaks). (Gustavo) + . Fixed bug #62083 (grapheme_extract() memory leaks). (Gustavo) . Fixed bug #62082 (Memory corruption in internal get_icu_disp_value_src_php function). (Gustavo) . Fixed bug #62081 (IntlDateFormatter constructor leaks memory when called From e08566c6139461db9dbf0f6c2e870d67923ee587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Wed, 23 May 2012 15:48:50 +0200 Subject: [PATCH 3/3] Fixed bug #62017 IntlDateFormatter constructor would release some resources under certain error conditions. --- NEWS | 2 + ext/intl/dateformat/dateformat.c | 64 ++++++++++++++++++++++---------- ext/intl/tests/bug62017.phpt | 22 +++++++++++ 3 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 ext/intl/tests/bug62017.phpt diff --git a/NEWS b/NEWS index 900dd5c5e98..35f0d6ba7d8 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ PHP NEWS . Fixed bug #62081 (IntlDateFormatter constructor leaks memory when called twice). (Gustavo) . Fixed bug #62070 (Collator::getSortKey() returns garbage). (Gustavo) + . Fixed bug #62017 (datefmt_create with incorrectly encoded timezone leaks + pattern). (Gustavo) - XML Writer: . Fixed bug #62064 (memory leak in the XML Writer module). diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.c index 05ba19e7de8..6c0c52257b9 100755 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.c @@ -109,14 +109,27 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) /* Convert pattern (if specified) to UTF-16. */ if( pattern_str && pattern_str_len>0 ){ - intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); - INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: error converting pattern to UTF-16"); + intl_convert_utf8_to_utf16(&svalue, &slength, + pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); + if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + /* object construction -> only set global error */ + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " + "error converting pattern to UTF-16", 0 TSRMLS_CC); + goto error; + } } + + /* resources allocated from now on */ /* Convert pattern (if specified) to UTF-16. */ if( timezone_str && timezone_str_len >0 ){ - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(dfo)); - INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: error converting timezone_str to UTF-16" ); + intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, + timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(dfo)); + if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " + "error converting timezone_str to UTF-16", 0 TSRMLS_CC); + goto error; + } } if(locale_len == 0) { @@ -130,23 +143,23 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } /* Set the calendar if passed */ - if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo)) && calendar) { - ucal_obj = ucal_open( timezone_utf16, timezone_utf16_len, locale, calendar, &INTL_DATA_ERROR_CODE(dfo) ); - if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { - udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); + if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + if (calendar) { + ucal_obj = ucal_open(timezone_utf16, timezone_utf16_len, locale, + calendar, &INTL_DATA_ERROR_CODE(dfo)); + if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); + } else { + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create" + ": error opening calendar", 0 TSRMLS_CC); + goto error; + } } - } - - if(svalue) - { - efree(svalue); + } else { + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " + "formatter creation failed", 0 TSRMLS_CC); + goto error; } - if(timezone_utf16) - { - efree(timezone_utf16); - } - - INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: date formatter creation failed"); /* Set the class variables */ dfo->date_type = date_type; @@ -155,6 +168,19 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) if( timezone_str && timezone_str_len > 0){ dfo->timezone_id = estrndup( timezone_str, timezone_str_len); } + +error: + if (svalue) { + efree(svalue); + } + if (timezone_utf16) { + efree(timezone_utf16); + } + if (U_FAILURE(intl_error_get_code(NULL TSRMLS_CC))) { + /* free_object handles partially constructed instances fine */ + zval_dtor(return_value); + RETVAL_NULL(); + } } /* }}} */ diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt new file mode 100644 index 00000000000..13c4fe5df0b --- /dev/null +++ b/ext/intl/tests/bug62017.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #62017: datefmt_create with incorrectly encoded timezone leaks pattern +--SKIPIF-- +