From d8f08192effdd786e00dfc4da8ee762b066382b6 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 4 Aug 2011 00:59:43 +0000 Subject: [PATCH] - Fixed possible efree(NULL) (bug #55296) --- ext/intl/collator/collator_compare.c | 12 +++-- ext/intl/dateformat/dateformat_attr.c | 4 +- ext/intl/formatter/formatter_attr.c | 12 +++-- ext/intl/formatter/formatter_parse.c | 8 ++- ext/intl/grapheme/grapheme_string.c | 25 +++++++--- ext/intl/grapheme/grapheme_util.c | 49 ++++++++++++++----- ext/intl/idn/idn.c | 4 +- ext/intl/msgformat/msgformat_attr.c | 4 +- ext/intl/msgformat/msgformat_parse.c | 4 +- ext/intl/normalizer/normalizer_normalize.c | 8 ++- .../transliterator/transliterator_methods.c | 8 ++- 11 files changed, 103 insertions(+), 35 deletions(-) diff --git a/ext/intl/collator/collator_compare.c b/ext/intl/collator/collator_compare.c index 4e7b3a7d49..840855661c 100755 --- a/ext/intl/collator/collator_compare.c +++ b/ext/intl/collator/collator_compare.c @@ -74,7 +74,9 @@ PHP_FUNCTION( collator_compare ) /* Set error messages. */ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting first argument to UTF-16", 0 TSRMLS_CC ); - efree( ustr1 ); + if (ustr1) { + efree( ustr1 ); + } RETURN_FALSE; } @@ -88,8 +90,12 @@ PHP_FUNCTION( collator_compare ) /* Set error messages. */ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting second argument to UTF-16", 0 TSRMLS_CC ); - efree( ustr1 ); - efree( ustr2 ); + if (ustr1) { + efree( ustr1 ); + } + if (ustr2) { + efree( ustr2 ); + } RETURN_FALSE; } diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index 7c6cef9536..6131cedc95 100755 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -276,7 +276,9 @@ PHP_FUNCTION( datefmt_set_pattern ) udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized, svalue, slength); - efree(svalue); + if (svalue) { + efree(svalue); + } INTL_METHOD_CHECK_STATUS(dfo, "Error setting symbol value"); RETURN_TRUE; diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.c index 46d61fb1fc..b306bbedeb 100755 --- a/ext/intl/formatter/formatter_attr.c +++ b/ext/intl/formatter/formatter_attr.c @@ -233,7 +233,9 @@ PHP_FUNCTION( numfmt_set_text_attribute ) /* Actually set new attribute value. */ unum_setTextAttribute(FORMATTER_OBJECT(nfo), attribute, svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); - efree(svalue); + if (svalue) { + efree(svalue); + } INTL_METHOD_CHECK_STATUS( nfo, "Error setting text attribute" ); RETURN_TRUE; @@ -326,7 +328,9 @@ PHP_FUNCTION( numfmt_set_symbol ) /* Actually set the symbol. */ unum_setSymbol(FORMATTER_OBJECT(nfo), symbol, svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); - efree(svalue); + if (svalue) { + efree(svalue); + } INTL_METHOD_CHECK_STATUS( nfo, "Error setting symbol value" ); RETURN_TRUE; @@ -406,7 +410,9 @@ PHP_FUNCTION( numfmt_set_pattern ) /* TODO: add parse error information */ unum_applyPattern(FORMATTER_OBJECT(nfo), 0, svalue, slength, NULL, &INTL_DATA_ERROR_CODE(nfo)); - efree(svalue); + if (svalue) { + efree(svalue); + } INTL_METHOD_CHECK_STATUS( nfo, "Error setting pattern value" ); RETURN_TRUE; diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.c index b73095d3e4..cbdde855de 100755 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.c @@ -107,7 +107,9 @@ PHP_FUNCTION( numfmt_parse ) ZVAL_LONG(zposition, position); } - efree(sstr); + if (sstr) { + efree(sstr); + } INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" ); } @@ -161,7 +163,9 @@ PHP_FUNCTION( numfmt_parse_currency ) zval_dtor(zposition); ZVAL_LONG(zposition, position); } - efree(sstr); + if (sstr) { + efree(sstr); + } INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" ); /* Convert parsed currency to UTF-8 and pass it back to caller. */ diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 1784d028a8..095cc2a046 100755 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -84,13 +84,17 @@ PHP_FUNCTION(grapheme_strlen) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( ustring ); + if (ustring) { + efree( ustring ); + } RETURN_NULL(); } ret_len = grapheme_split_string(ustring, ustring_len, NULL, 0 TSRMLS_CC ); - efree( ustring ); + if (ustring) { + efree( ustring ); + } if (ret_len >= 0) { RETVAL_LONG(ret_len); @@ -447,7 +451,9 @@ PHP_FUNCTION(grapheme_substr) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( ustr ); + if (ustr) { + efree( ustr ); + } RETURN_FALSE; } @@ -485,7 +491,9 @@ PHP_FUNCTION(grapheme_substr) intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: start not contained in string", 1 TSRMLS_CC ); - efree(ustr); + if (ustr) { + efree(ustr); + } ubrk_close(bi); RETURN_FALSE; } @@ -499,7 +507,9 @@ PHP_FUNCTION(grapheme_substr) status = U_ZERO_ERROR; intl_convert_utf16_to_utf8((char **)&sub_str, &sub_str_len, ustr + sub_str_start_pos, ustr_len - sub_str_start_pos, &status); - efree( ustr ); + if (ustr) { + efree( ustr ); + } ubrk_close( bi ); if ( U_FAILURE( status ) ) { @@ -509,6 +519,7 @@ PHP_FUNCTION(grapheme_substr) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8", 0 TSRMLS_CC ); + efree( sub_str ); RETURN_FALSE; @@ -897,7 +908,9 @@ PHP_FUNCTION(grapheme_extract) ret_pos = (*grapheme_extract_iters[extract_type])(bi, size, pstr, str_len); - efree(ustr); + if (ustr) { + efree(ustr); + } ubrk_close(bi); if ( NULL != next ) { diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index 1978d274a0..db56431648 100755 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -170,7 +170,9 @@ grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned c /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( uhaystack ); + if (uhaystack) { + efree( uhaystack ); + } return -1; } @@ -187,7 +189,9 @@ grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned c if ( NULL == puhaystack ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 TSRMLS_CC ); - efree( uhaystack ); + if (uhaystack) { + efree( uhaystack ); + } ubrk_close (bi); return -1; } @@ -203,8 +207,12 @@ grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned c /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( uhaystack ); - efree( uneedle ); + if (uhaystack) { + efree( uhaystack ); + } + if (uneedle) { + efree( uneedle ); + } ubrk_close (bi); return -1; } @@ -260,8 +268,12 @@ grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned c } exit: - efree( uhaystack ); - efree( uneedle ); + if (uhaystack) { + efree( uhaystack ); + } + if (uneedle) { + efree( uneedle ); + } ubrk_close (bi); return ret_pos; @@ -295,7 +307,9 @@ grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned ch /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( uhaystack ); + if (uhaystack) { + efree( uhaystack ); + } return -1; } @@ -310,8 +324,9 @@ grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned ch if ( NULL == puhaystack ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 TSRMLS_CC ); - - efree( uhaystack ); + if (uhaystack) { + efree( uhaystack ); + } ubrk_close (bi); return -1; @@ -332,8 +347,12 @@ grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned ch /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( uhaystack ); - efree( uneedle ); + if (uhaystack) { + efree( uhaystack ); + } + if (uneedle) { + efree( uneedle ); + } ubrk_close (bi); return -1; @@ -347,8 +366,12 @@ grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned ch *puchar_pos = ubrk_current(bi); - efree( uhaystack ); - efree( uneedle ); + if (uhaystack) { + efree( uhaystack ); + } + if (uneedle) { + efree( uneedle ); + } ubrk_close (bi); return ret_pos; diff --git a/ext/intl/idn/idn.c b/ext/intl/idn/idn.c index e7a3b6a6d2..23cd0ea872 100644 --- a/ext/intl/idn/idn.c +++ b/ext/intl/idn/idn.c @@ -85,7 +85,9 @@ static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS, int mode) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree(ustring); + if (ustring) { + efree(ustring); + } RETURN_FALSE; } else { UParseError parse_error; diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.c index 47350b2b45..cf34665142 100755 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.c @@ -90,7 +90,9 @@ PHP_FUNCTION( msgfmt_set_pattern ) /* TODO: add parse error information */ umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, NULL, &INTL_DATA_ERROR_CODE(mfo)); - efree(spattern); + if (spattern) { + efree(spattern); + } INTL_METHOD_CHECK_STATUS(mfo, "Error setting symbol value"); if(mfo->mf_data.orig_format) { diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index 61c5213f05..8393d4c6e3 100755 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -40,7 +40,9 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, int src_ INTL_METHOD_CHECK_STATUS(mfo, "Converting parse string failed"); umsg_parse_helper(MSG_FORMAT_OBJECT(mfo), &count, &fargs, usource, usrc_len, &INTL_DATA_ERROR_CODE(mfo)); - efree(usource); + if (usource) { + efree(usource); + } INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed"); array_init(return_value); diff --git a/ext/intl/normalizer/normalizer_normalize.c b/ext/intl/normalizer/normalizer_normalize.c index 482c4a01e5..466ab97e12 100755 --- a/ext/intl/normalizer/normalizer_normalize.c +++ b/ext/intl/normalizer/normalizer_normalize.c @@ -96,7 +96,9 @@ PHP_FUNCTION( normalizer_normalize ) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC ); - efree( uinput ); + if (uinput) { + efree( uinput ); + } RETURN_FALSE; } @@ -220,7 +222,9 @@ PHP_FUNCTION( normalizer_is_normalized ) /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting string to UTF-16.", 0 TSRMLS_CC ); - efree( uinput ); + if (uinput) { + efree( uinput ); + } RETURN_FALSE; } diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c index e7ea329cef..d0cfb9790d 100644 --- a/ext/intl/transliterator/transliterator_methods.c +++ b/ext/intl/transliterator/transliterator_methods.c @@ -60,7 +60,9 @@ static int create_transliterator( char *str_id, int str_id_len, long direction, /* Open ICU Transliterator. */ utrans = utrans_openU( ustr_id, ustr_id_len, (UTransDirection ) direction, NULL, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) ); - efree( ustr_id ); + if (ustr_id) { + efree( ustr_id ); + } if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) ) { @@ -172,7 +174,9 @@ PHP_FUNCTION( transliterator_create_from_rules ) /* Open ICU Transliterator. */ utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction, ustr_rules, ustr_rules_len, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) ); - efree( ustr_rules ); + if (ustr_rules) { + efree( ustr_rules ); + } intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to ) TSRMLS_CC ); if( U_FAILURE( INTL_DATA_ERROR_CODE( to ) ) ) -- 2.40.0