Skip to content

Commit

Permalink
Fix #60192 SegFault when Collator not constructed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
winks committed Nov 2, 2011
1 parent b64e91d commit c2874a8
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/intl/collator/collator_compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ PHP_FUNCTION( collator_compare )
RETURN_FALSE;
}

if (!co || !co->ucoll) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
}

/* Then compare them. */
result = ucol_strcoll(
co->ucoll,
Expand Down
4 changes: 4 additions & 0 deletions ext/intl/collator/collator_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ PHP_FUNCTION( collator_get_locale )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;

if (!co || !co->ucoll) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
}

/* Get locale by specified type. */
locale_name = (char*) ucol_getLocaleByType(
co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
Expand Down
12 changes: 12 additions & 0 deletions ext/intl/collator/collator_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2
/* Fetch collator object. */
co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC );

if (!co || !co->ucoll) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
}

/* Compare the strings using ICU. */
result->value.lval = ucol_strcoll(
co->ucoll,
Expand Down Expand Up @@ -441,6 +445,10 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
/* Get sort key, reallocating the buffer if needed. */
bufLeft = sortKeyBufSize - sortKeyBufOffset;

if (!co || !co->ucoll) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
}

sortKeyLen = ucol_getSortKey( co->ucoll,
utf16_buf,
utf16_len,
Expand Down Expand Up @@ -571,6 +579,10 @@ PHP_FUNCTION( collator_get_sort_key )
RETURN_FALSE;
}

if (!co || !co->ucoll) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
}

key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0);
if(!key_len) {
efree( ustr );
Expand Down
20 changes: 20 additions & 0 deletions ext/intl/tests/bug60192-compare.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #60192 (SegFault when Collator not constructed properly)
--SKIPIF--
<?php
if (!extension_loaded('intl')) { die('skip intl extension not available'); }
?>
--FILE--
<?php

class Collator2 extends Collator{
public function __construct() {
// ommitting parent::__construct($someLocale);
}
}

$c = new Collator2();
$c->compare('h', 'H');
--EXPECTF--

Fatal error: Collator::compare(): Object not initialized in %s on line %d
20 changes: 20 additions & 0 deletions ext/intl/tests/bug60192-getlocale.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #60192 (SegFault when Collator not constructed properly)
--SKIPIF--
<?php
if (!extension_loaded('intl')) { die('skip intl extension not available'); }
?>
--FILE--
<?php

class Collator2 extends Collator{
public function __construct() {
// ommitting parent::__construct($someLocale);
}
}

$c = new Collator2();
$c->getLocale(Locale::ACTUAL_LOCALE);
--EXPECTF--

Fatal error: Collator::getLocale(): Object not initialized in %s on line %d
20 changes: 20 additions & 0 deletions ext/intl/tests/bug60192-getsortkey.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #60192 (SegFault when Collator not constructed properly)
--SKIPIF--
<?php
if (!extension_loaded('intl')) { die('skip intl extension not available'); }
?>
--FILE--
<?php

class Collator2 extends Collator{
public function __construct() {
// ommitting parent::__construct($someLocale);
}
}

$c = new Collator2();
$c->getSortKey('h');
--EXPECTF--

Fatal error: Collator::getSortKey(): Object not initialized in %s on line %d
21 changes: 21 additions & 0 deletions ext/intl/tests/bug60192-sort.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #60192 (SegFault when Collator not constructed properly)
--SKIPIF--
<?php
if (!extension_loaded('intl')) { die('skip intl extension not available'); }
?>
--FILE--
<?php

class Collator2 extends Collator{
public function __construct() {
// ommitting parent::__construct($someLocale);
}
}

$c = new Collator2();
$a = array('a', 'b');
$c->sort($a);
--EXPECTF--

Fatal error: Collator::sort(): Object not initialized in %s on line %d
21 changes: 21 additions & 0 deletions ext/intl/tests/bug60192-sortwithsortkeys.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #60192 (SegFault when Collator not constructed properly)
--SKIPIF--
<?php
if (!extension_loaded('intl')) { die('skip intl extension not available'); }
?>
--FILE--
<?php

class Collator2 extends Collator{
public function __construct() {
// ommitting parent::__construct($someLocale);
}
}

$c = new Collator2();
$a = array('a', 'b');
$c->sortWithSortKeys($a);
--EXPECTF--

Fatal error: Collator::sortWithSortKeys(): Object not initialized in %s on line %d

0 comments on commit c2874a8

Please sign in to comment.