ICU-9396 Accept NULL pointer with length of 0 in ucol_strcoll and ucol_strcollUTF8. Also added some test case verifying the behavior.

X-SVN-Rev: 34363
This commit is contained in:
Yoshito Umaoka 2013-09-17 21:08:10 +00:00
parent 6144e1bad2
commit 271e788d65
4 changed files with 118 additions and 12 deletions

View file

@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cal", "..\samples\cal\cal.vcxproj", "{F7659D77-09CF-4FE9-ACEE-927287AA9509}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cintltst", "..\test\cintltst\cintltst.vcxproj", "{3D1246AE-1B32-479B-BECA-AEFA97BE2321}"
@ -68,10 +68,6 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplug", "..\tools\icuinfo\testplug.vcxproj", "{659D0C08-D4ED-4BF3-B02B-2D8D4B5A7A7A}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
@ -89,12 +85,10 @@ Global
{F7659D77-09CF-4FE9-ACEE-927287AA9509}.Release|x64.Build.0 = Release|x64
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Debug|Win32.ActiveCfg = Debug|Win32
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Debug|Win32.Build.0 = Debug|Win32
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Debug|x64.ActiveCfg = Debug|x64
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Debug|x64.Build.0 = Debug|x64
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Debug|x64.ActiveCfg = Debug|Win32
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Release|Win32.ActiveCfg = Release|Win32
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Release|Win32.Build.0 = Release|Win32
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Release|x64.ActiveCfg = Release|x64
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Release|x64.Build.0 = Release|x64
{3D1246AE-1B32-479B-BECA-AEFA97BE2321}.Release|x64.ActiveCfg = Release|Win32
{73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D}.Debug|Win32.ActiveCfg = Debug|Win32
{73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D}.Debug|Win32.Build.0 = Debug|Win32
{73C0A65B-D1F2-4DE1-B3A6-15DAD2C23F3D}.Debug|x64.ActiveCfg = Debug|x64
@ -339,4 +333,8 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
EndGlobal

View file

@ -8477,7 +8477,7 @@ ucol_strcoll( const UCollator *coll,
UTRACE_DATA2(UTRACE_VERBOSE, "target string = %vh ", target, targetLength);
}
if(source == NULL || target == NULL) {
if((source == NULL && sourceLength != 0) || (target == NULL && targetLength != 0)) {
// do not crash, but return. Should have
// status argument to return error.
UTRACE_EXIT_VALUE(UCOL_EQUAL);
@ -8613,7 +8613,7 @@ ucol_strcollUTF8(
return UCOL_EQUAL;
}
if(source == NULL || target == NULL) {
if((source == NULL && sourceLength != 0) || (target == NULL && targetLength != 0)) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
UTRACE_EXIT_VALUE_STATUS(UCOL_EQUAL, *status);
return UCOL_EQUAL;

View file

@ -85,6 +85,7 @@ void addCollAPITest(TestNode** root)
addTest(root, &TestOpenVsOpenRules, "tscoll/capitst/TestOpenVsOpenRules");
addTest(root, &TestBengaliSortKey, "tscoll/capitst/TestBengaliSortKey");
addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale");
addTest(root, &TestStrcollNull, "tscoll/capitst/TestStrcollNull");
}
void TestGetSetAttr(void) {
@ -2406,5 +2407,106 @@ static void TestGetKeywordValuesForLocale(void) {
}
}
static void TestStrcollNull(void) {
UErrorCode status = U_ZERO_ERROR;
UCollator *coll;
const UChar u16asc[] = {0x0049, 0x0042, 0x004D, 0};
const int32_t u16ascLen = 3;
const UChar u16han[] = {0x5c71, 0x5ddd, 0};
const int32_t u16hanLen = 2;
const char u8asc[] = {0x49, 0x42, 0x4D, 0};
const int32_t u8ascLen = 3;
const char u8han[] = {0xE5, 0xB1, 0xB1, 0xE5, 0xB7, 0x9D, 0};
const int32_t u8hanLen = 6;
coll = ucol_open(NULL, &status);
if (U_FAILURE(status)) {
log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status));
return;
}
/* UChar API */
if (ucol_strcoll(coll, NULL, 0, NULL, 0) != 0) {
log_err("ERROR : ucol_strcoll NULL/0 and NULL/0");
}
if (ucol_strcoll(coll, NULL, -1, NULL, 0) != 0) {
/* No error arg, should return equal without crash */
log_err("ERROR : ucol_strcoll NULL/-1 and NULL/0");
}
if (ucol_strcoll(coll, u16asc, -1, NULL, 10) != 0) {
/* No error arg, should return equal without crash */
log_err("ERROR : ucol_strcoll u16asc/u16ascLen and NULL/10");
}
if (ucol_strcoll(coll, u16asc, -1, NULL, 0) <= 0) {
log_err("ERROR : ucol_strcoll u16asc/-1 and NULL/0");
}
if (ucol_strcoll(coll, NULL, 0, u16asc, -1) >= 0) {
log_err("ERROR : ucol_strcoll NULL/0 and u16asc/-1");
}
if (ucol_strcoll(coll, u16asc, u16ascLen, NULL, 0) <= 0) {
log_err("ERROR : ucol_strcoll u16asc/u16ascLen and NULL/0");
}
if (ucol_strcoll(coll, u16han, -1, NULL, 0) <= 0) {
log_err("ERROR : ucol_strcoll u16han/-1 and NULL/0");
}
if (ucol_strcoll(coll, NULL, 0, u16han, -1) >= 0) {
log_err("ERROR : ucol_strcoll NULL/0 and u16han/-1");
}
if (ucol_strcoll(coll, NULL, 0, u16han, u16hanLen) >= 0) {
log_err("ERROR : ucol_strcoll NULL/0 and u16han/u16hanLen");
}
/* UTF-8 API */
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, NULL, 0, NULL, 0, &status) != 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 NULL/0 and NULL/0");
}
status = U_ZERO_ERROR;
ucol_strcollUTF8(coll, NULL, -1, NULL, 0, &status);
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
log_err("ERROR: ucol_strcollUTF8 NULL/-1 and NULL/0, should return U_ILLEGAL_ARGUMENT_ERROR");
}
status = U_ZERO_ERROR;
ucol_strcollUTF8(coll, u8asc, u8ascLen, NULL, 10, &status);
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
log_err("ERROR: ucol_strcollUTF8 u8asc/u8ascLen and NULL/10, should return U_ILLEGAL_ARGUMENT_ERROR");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, u8asc, -1, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 u8asc/-1 and NULL/0");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, NULL, 0, u8asc, -1, &status) >= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8asc/-1");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, u8asc, u8ascLen, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 u8asc/u8ascLen and NULL/0");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, u8han, -1, NULL, 0, &status) <= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 u8han/-1 and NULL/0");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, NULL, 0, u8han, -1, &status) >= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/-1");
}
status = U_ZERO_ERROR;
if (ucol_strcollUTF8(coll, NULL, 0, u8han, u8hanLen, &status) >= 0 || U_FAILURE(status)) {
log_err("ERROR : ucol_strcollUTF8 NULL/0 and u8han/u8hanLen");
}
ucol_close(coll);
}
#endif /* #if !UCONFIG_NO_COLLATION */

View file

@ -1,5 +1,5 @@
/********************************************************************
* Copyright (c) 1997-2009 International Business Machines
* Copyright (c) 1997-2013 International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************/
/********************************************************************************
@ -129,6 +129,12 @@
* Test getKeywordValuesForLocale API
*/
static void TestGetKeywordValuesForLocale(void);
/**
* test strcoll with null arg
*/
static void TestStrcollNull(void);
#endif /* #if !UCONFIG_NO_COLLATION */
#endif