Skip to content

Commit 2a29add

Browse files
committed
Fix bug #67397 (Buffer overflow in locale_get_display_name->uloc_getDisplayName (libicu 4.8.1))
1 parent 5ecee6e commit 2a29add

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/intl/locale/locale_methods.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME
497497
RETURN_FALSE;
498498
}
499499

500+
if(loc_name_len > ULOC_FULLNAME_CAPACITY) {
501+
/* See bug 67397: overlong locale names cause trouble in uloc_getDisplayName */
502+
spprintf(&msg , 0, "locale_get_display_%s : name too long", tag_name );
503+
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, msg , 1 TSRMLS_CC );
504+
efree(msg);
505+
RETURN_FALSE;
506+
}
507+
500508
if(loc_name_len == 0) {
501509
loc_name = intl_locale_get_default(TSRMLS_C);
502510
}

ext/intl/tests/bug67397.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #67397 (Buffer overflow in locale_get_display_name->uloc_getDisplayName (libicu 4.8.1))
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
function ut_main()
9+
{
10+
$ret = var_export(ut_loc_get_display_name(str_repeat('*', 256), 'en_us'), true);
11+
$ret .= "\n";
12+
$ret .= var_export(intl_get_error_message(), true);
13+
return $ret;
14+
}
15+
16+
include_once( 'ut_common.inc' );
17+
ut_run();
18+
?>
19+
--EXPECTF--
20+
false
21+
'locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR'

0 commit comments

Comments
 (0)