stas                                     Fri, 19 Nov 2010 23:22:55 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=305571

Log:
Fix invalid args bugs by Maksymilian Arciemowicz

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_attr.c
    U   php/php-src/branches/PHP_5_3/ext/intl/formatter/formatter_attr.c
    U   php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_get_locale.phpt
    U   
php/php-src/branches/PHP_5_3/ext/intl/tests/formatter_get_set_symbol.phpt
    U   php/php-src/trunk/ext/intl/dateformat/dateformat_attr.c
    U   php/php-src/trunk/ext/intl/formatter/formatter_attr.c
    U   php/php-src/trunk/ext/intl/tests/dateformat_get_locale.phpt
    U   php/php-src/trunk/ext/intl/tests/formatter_get_set_symbol.phpt

Modified: php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_attr.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_attr.c  
2010-11-19 22:06:44 UTC (rev 305570)
+++ php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_attr.c  
2010-11-19 23:22:55 UTC (rev 305571)
@@ -309,6 +309,7 @@
        DATE_FORMAT_METHOD_FETCH_OBJECT;

        loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), 
loc_type,&INTL_DATA_ERROR_CODE(dfo));
+       INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale");
        RETURN_STRING(loc, 1);
 }
 /* }}} */

Modified: php/php-src/branches/PHP_5_3/ext/intl/formatter/formatter_attr.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/formatter/formatter_attr.c    
2010-11-19 22:06:44 UTC (rev 305570)
+++ php/php-src/branches/PHP_5_3/ext/intl/formatter/formatter_attr.c    
2010-11-19 23:22:55 UTC (rev 305571)
@@ -250,7 +250,7 @@
        long symbol;
        UChar value_buf[4];
        UChar *value = value_buf;
-       int length = USIZE(value);
+       int length = USIZE(value_buf);
        FORMATTER_METHOD_INIT_VARS;

        /* Parse parameters. */
@@ -262,12 +262,17 @@

                RETURN_FALSE;
        }
+
+       if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, 
"numfmt_get_symbol: invalid symbol value", 0 TSRMLS_CC );
+               RETURN_FALSE;
+       }

        /* Fetch the object. */
        FORMATTER_METHOD_FETCH_OBJECT;

        length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value_buf, 
length, &INTL_DATA_ERROR_CODE(nfo));
-       if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= 
USIZE( value )) {
+       if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= 
USIZE( value_buf )) {
                ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
                INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
                value = eumalloc(length);

Modified: php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_get_locale.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_get_locale.phpt      
2010-11-19 22:06:44 UTC (rev 305570)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_get_locale.phpt      
2010-11-19 23:22:55 UTC (rev 305571)
@@ -29,6 +29,12 @@
                $res_str .= "\nAfter call to get_locale :  locale= $locale";
                $res_str .= "\n";
        }
+       $badvals = array(100, -1, 4294901761);
+       foreach($badvals as $badval) {
+               if(ut_datefmt_get_locale($fmt, $badval)) {
+                       $res_str .= "datefmt_get_locale should return false for 
bad argument $badval\n";
+               }
+       }

        return $res_str;


Modified: 
php/php-src/branches/PHP_5_3/ext/intl/tests/formatter_get_set_symbol.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/formatter_get_set_symbol.phpt   
2010-11-19 22:06:44 UTC (rev 305570)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/formatter_get_set_symbol.phpt   
2010-11-19 23:22:55 UTC (rev 305571)
@@ -73,7 +73,12 @@
         // Restore attribute's symbol.
         ut_nfmt_set_symbol( $fmt, $symb, $orig_val );
     }
-
+    $badvals = array(2147483648, -2147483648, -1, 4294901761);
+    foreach($badvals as $badval) {
+           if(ut_nfmt_get_symbol( $fmt, 2147483648 ))  {
+               $res_str .= "Bad value $badval should return false!\n";
+           }
+    }
     return $res_str;
 }


Modified: php/php-src/trunk/ext/intl/dateformat/dateformat_attr.c
===================================================================
--- php/php-src/trunk/ext/intl/dateformat/dateformat_attr.c     2010-11-19 
22:06:44 UTC (rev 305570)
+++ php/php-src/trunk/ext/intl/dateformat/dateformat_attr.c     2010-11-19 
23:22:55 UTC (rev 305571)
@@ -309,6 +309,7 @@
        DATE_FORMAT_METHOD_FETCH_OBJECT;

        loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), 
loc_type,&INTL_DATA_ERROR_CODE(dfo));
+       INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale");
        RETURN_STRING(loc, 1);
 }
 /* }}} */

Modified: php/php-src/trunk/ext/intl/formatter/formatter_attr.c
===================================================================
--- php/php-src/trunk/ext/intl/formatter/formatter_attr.c       2010-11-19 
22:06:44 UTC (rev 305570)
+++ php/php-src/trunk/ext/intl/formatter/formatter_attr.c       2010-11-19 
23:22:55 UTC (rev 305571)
@@ -250,7 +250,7 @@
        long symbol;
        UChar value_buf[4];
        UChar *value = value_buf;
-       int length = USIZE(value);
+       int length = USIZE(value_buf);
        FORMATTER_METHOD_INIT_VARS;

        /* Parse parameters. */
@@ -262,12 +262,17 @@

                RETURN_FALSE;
        }
+
+       if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
+               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, 
"numfmt_get_symbol: invalid symbol value", 0 TSRMLS_CC );
+               RETURN_FALSE;
+       }

        /* Fetch the object. */
        FORMATTER_METHOD_FETCH_OBJECT;

        length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value_buf, 
length, &INTL_DATA_ERROR_CODE(nfo));
-       if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= 
USIZE( value )) {
+       if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= 
USIZE( value_buf )) {
                ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
                INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
                value = eumalloc(length);

Modified: php/php-src/trunk/ext/intl/tests/dateformat_get_locale.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/dateformat_get_locale.phpt 2010-11-19 
22:06:44 UTC (rev 305570)
+++ php/php-src/trunk/ext/intl/tests/dateformat_get_locale.phpt 2010-11-19 
23:22:55 UTC (rev 305571)
@@ -29,6 +29,12 @@
                $res_str .= "\nAfter call to get_locale :  locale= $locale";
                $res_str .= "\n";
        }
+       $badvals = array(100, -1, 4294901761);
+       foreach($badvals as $badval) {
+               if(ut_datefmt_get_locale($fmt, $badval)) {
+                       $res_str .= "datefmt_get_locale should return false for 
bad argument $badval\n";
+               }
+       }

        return $res_str;


Modified: php/php-src/trunk/ext/intl/tests/formatter_get_set_symbol.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/formatter_get_set_symbol.phpt      
2010-11-19 22:06:44 UTC (rev 305570)
+++ php/php-src/trunk/ext/intl/tests/formatter_get_set_symbol.phpt      
2010-11-19 23:22:55 UTC (rev 305571)
@@ -73,7 +73,12 @@
         // Restore attribute's symbol.
         ut_nfmt_set_symbol( $fmt, $symb, $orig_val );
     }
-
+    $badvals = array(2147483648, -2147483648, -1, 4294901761);
+    foreach($badvals as $badval) {
+           if(ut_nfmt_get_symbol( $fmt, 2147483648 ))  {
+               $res_str .= "Bad value $badval should return false!\n";
+           }
+    }
     return $res_str;
 }


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to