com php-src: Fix bug #66873: check if obj->src is set: NEWS ext/intl/converter/converter.c ext/intl/tests/uconverter_bug 66873.phpt
| From: | Stanislav Malyshev | Date: | Mon, 17 Mar 2014 08:19:02 +0000 |
| Subject: | com php-src: Fix bug #66873: check if obj->src is set: NEWS ext/intl/converter/converter.c ext/intl/tests/uconverter_bug 66873.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-76504@lists.php.net to get a copy of this message | ||
Commit: 66bf216c66b36c3a5379368747f21470b4dd3d27
Author: Stanislav Malyshev <stas@php.net> Mon, 17 Mar 2014 01:17:09 -0700
Parents: 80fa2ff646f804951a72a580976d09ca28a98444
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=66bf216c66b36c3a5379368747f21470b4dd3d27
Log:
Fix bug #66873: check if obj->src is set
Bugs:
https://bugs.php.net/66873
Changed paths:
M NEWS
M ext/intl/converter/converter.c
A ext/intl/tests/uconverter_bug66873.phpt
Diff:
diff --git a/NEWS b/NEWS
index e2d04b5..8a5cf73 100644
--- a/NEWS
+++ b/NEWS
@@ -29,11 +29,15 @@ PHP NEWS
. hash_pbkdf2() now works correctly if the $length argument is not specified.
(Nikita)
+- Intl:
+ . Fixed bug #66873 (A reproductible crash in UConverter when given invalid
+ encoding) (Stas)
+
- Mail:
. Fixed bug #66535 (Don't add newline after X-PHP-Originating-Script) (Tjerk)
- MySQLi:
- . Fixed bug #66762i (Segfault in mysqli_stmt::bind_result() when link closed)
+ . Fixed bug #66762 (Segfault in mysqli_stmt::bind_result() when link closed)
(Remi)
- OPCache
diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c
index 5f2d1e7..a3381bf 100644
--- a/ext/intl/converter/converter.c
+++ b/ext/intl/converter/converter.c
@@ -57,6 +57,8 @@ static inline void php_converter_throw_failure(php_converter_object *objval, UEr
/* {{{ php_converter_default_callback */
static void php_converter_default_callback(zval *return_value, zval *zobj, long reason, zval *error
TSRMLS_DC) {
+ zval_dtor(error);
+ ZVAL_LONG(error, U_ZERO_ERROR);
/* Basic functionality so children can call parent::toUCallback() */
switch (reason) {
case UCNV_UNASSIGNED:
@@ -66,7 +68,16 @@ static void php_converter_default_callback(zval *return_value, zval *zobj, long
php_converter_object *objval = (php_converter_object*)CONV_GET(zobj);
char chars[127];
int8_t chars_len = sizeof(chars);
- UErrorCode error = U_ZERO_ERROR;
+ UErrorCode uerror = U_ZERO_ERROR;
+ if(!objval->src) {
+ php_converter_throw_failure(objval, U_INVALID_STATE_ERROR TSRMLS_CC, "Source
Converter has not been initialized yet");
+ chars[0] = 0x1A;
+ chars[1] = 0;
+ chars_len = 1;
+ ZVAL_LONG(error, U_INVALID_STATE_ERROR);
+ RETVAL_STRINGL(chars, chars_len, 1);
+ return;
+ }
/* Yes, this is fairly wasteful at first glance,
* but considering that the alternative is to store
@@ -75,18 +86,17 @@ static void php_converter_default_callback(zval *return_value, zval *zobj, long
* I'd rather take the CPU hit here, than waste time
* storing a value I'm unlikely to use.
*/
- ucnv_getSubstChars(objval->src, chars, &chars_len, &error);
- if (U_FAILURE(error)) {
- THROW_UFAILURE(objval, "ucnv_getSubstChars", error);
+ ucnv_getSubstChars(objval->src, chars, &chars_len, &uerror);
+ if (U_FAILURE(uerror)) {
+ THROW_UFAILURE(objval, "ucnv_getSubstChars", uerror);
chars[0] = 0x1A;
chars[1] = 0;
chars_len = 1;
+ ZVAL_LONG(error, uerror);
}
RETVAL_STRINGL(chars, chars_len, 1);
}
}
- zval_dtor(error);
- ZVAL_LONG(error, U_ZERO_ERROR);
}
/* }}} */
diff --git a/ext/intl/tests/uconverter_bug66873.phpt b/ext/intl/tests/uconverter_bug66873.phpt
new file mode 100644
index 0000000..aa1045e
--- /dev/null
+++ b/ext/intl/tests/uconverter_bug66873.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #66873 - crash in UConverter with invalid encoding
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+ $o = new UConverter(1, 1);
+ $o->toUCallback(1, 1, 1, $b);
+ var_dump($o->getErrorCode());
+--EXPECT--
+int(27)