mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 05:55:35 +00:00
ICU-5540 add domain name and domain label length checks
X-SVN-Rev: 20862
This commit is contained in:
parent
38d4426632
commit
ffa04cabe7
4 changed files with 133 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2003-2006, International Business Machines
|
||||
* Copyright (C) 2003-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -31,15 +31,19 @@ static const UChar ACE_PREFIX[] ={ 0x0078,0x006E,0x002d,0x002d } ;
|
|||
#define ACE_PREFIX_LENGTH 4
|
||||
|
||||
#define MAX_LABEL_LENGTH 63
|
||||
#define HYPHEN 0x002D
|
||||
/* The Max length of the labels should not be more than 64 */
|
||||
#define MAX_LABEL_BUFFER_SIZE 100
|
||||
#define MAX_IDN_BUFFER_SIZE 300
|
||||
/* The Max length of the labels should not be more than MAX_LABEL_LENGTH */
|
||||
#define MAX_LABEL_BUFFER_SIZE MAX_LABEL_LENGTH+1
|
||||
|
||||
#define MAX_DOMAIN_NAME_LENGTH 255
|
||||
/* The Max length of the domain names should not be more than MAX_DOMAIN_NAME_LENGTH */
|
||||
#define MAX_IDN_BUFFER_SIZE MAX_DOMAIN_NAME_LENGTH+1
|
||||
|
||||
#define LOWER_CASE_DELTA 0x0020
|
||||
#define HYPHEN 0x002D
|
||||
#define FULL_STOP 0x002E
|
||||
#define CAPITAL_A 0x0041
|
||||
#define CAPITAL_Z 0x005A
|
||||
#define LOWER_CASE_DELTA 0x0020
|
||||
#define FULL_STOP 0x002E
|
||||
|
||||
#define DATA_FILE_NAME "uidna"
|
||||
|
||||
inline static UChar
|
||||
|
@ -139,9 +143,8 @@ static inline UBool isLabelSeparator(UChar ch){
|
|||
// if *limit == separator then the length returned does not include
|
||||
// the separtor.
|
||||
static inline int32_t
|
||||
getNextSeparator(UChar *src,int32_t srcLength,
|
||||
UChar **limit,
|
||||
UBool *done){
|
||||
getNextSeparator(UChar *src, int32_t srcLength,
|
||||
UChar **limit, UBool *done){
|
||||
if(srcLength == -1){
|
||||
int32_t i;
|
||||
for(i=0 ; ;i++){
|
||||
|
@ -223,6 +226,11 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
|
|||
srcLength = u_strlen(src);
|
||||
}
|
||||
|
||||
if(srcLength > MAX_LABEL_LENGTH){
|
||||
*status = U_IDNA_LABEL_TOO_LONG_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// step 1
|
||||
for( j=0;j<srcLength;j++){
|
||||
if(src[j] > 0x7F){
|
||||
|
@ -357,7 +365,7 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
|
|||
goto CLEANUP;
|
||||
}
|
||||
}
|
||||
// step 8: verify the length of lable
|
||||
// step 8: verify the length of label
|
||||
if(reqLength > MAX_LABEL_LENGTH){
|
||||
*status = U_IDNA_LABEL_TOO_LONG_ERROR;
|
||||
}
|
||||
|
@ -433,6 +441,11 @@ _internal_toUnicode(const UChar* src, int32_t srcLength,
|
|||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(srcLength > MAX_LABEL_LENGTH){
|
||||
*status = U_IDNA_LABEL_TOO_LONG_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(srcIsASCII == FALSE){
|
||||
// step 2: process the string
|
||||
|
@ -624,7 +637,7 @@ uidna_toUnicode(const UChar* src, int32_t srcLength,
|
|||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
UStringPrepProfile* nameprep = usprep_open(NULL, DATA_FILE_NAME, status);
|
||||
|
||||
if(U_FAILURE(*status)){
|
||||
|
@ -722,6 +735,10 @@ uidna_IDNToASCII( const UChar *src, int32_t srcLength,
|
|||
|
||||
}
|
||||
|
||||
if(reqLength > MAX_DOMAIN_NAME_LENGTH){
|
||||
*status = U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR;
|
||||
}
|
||||
|
||||
usprep_close(nameprep);
|
||||
|
||||
return u_terminateUChars(dest, destCapacity, reqLength, status);
|
||||
|
@ -767,6 +784,7 @@ uidna_IDNToUnicode( const UChar* src, int32_t srcLength,
|
|||
if(labelLen==0 && done==FALSE){
|
||||
*status = U_IDNA_ZERO_LENGTH_LABEL_ERROR;
|
||||
}
|
||||
|
||||
labelReqLength = _internal_toUnicode(labelStart, labelLen,
|
||||
currentDest, remainingDestCapacity,
|
||||
options, nameprep,
|
||||
|
@ -778,7 +796,6 @@ uidna_IDNToUnicode( const UChar* src, int32_t srcLength,
|
|||
remainingDestCapacity = 0;
|
||||
}
|
||||
|
||||
|
||||
if(U_FAILURE(*status)){
|
||||
break;
|
||||
}
|
||||
|
@ -810,7 +827,11 @@ uidna_IDNToUnicode( const UChar* src, int32_t srcLength,
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(reqLength > MAX_DOMAIN_NAME_LENGTH){
|
||||
*status = U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR;
|
||||
}
|
||||
|
||||
usprep_close(nameprep);
|
||||
|
||||
return u_terminateUChars(dest, destCapacity, reqLength, status);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1996-2006, International Business Machines
|
||||
* Copyright (C) 1996-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*
|
||||
|
@ -732,6 +732,7 @@ typedef enum UErrorCode {
|
|||
U_IDNA_VERIFICATION_ERROR,
|
||||
U_IDNA_LABEL_TOO_LONG_ERROR,
|
||||
U_IDNA_ZERO_LENGTH_LABEL_ERROR,
|
||||
U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR,
|
||||
U_IDNA_ERROR_LIMIT,
|
||||
/*
|
||||
* Aliases for StringPrep
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2006, International Business Machines
|
||||
* Copyright (C) 1997-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
|
@ -164,7 +164,8 @@ _uIDNAErrorName[U_IDNA_ERROR_LIMIT - U_IDNA_ERROR_START] = {
|
|||
"U_IDNA_ACE_PREFIX_ERROR",
|
||||
"U_IDNA_VERIFICATION_ERROR",
|
||||
"U_IDNA_LABEL_TOO_LONG_ERROR",
|
||||
"U_IDNA_ZERO_LENGTH_LABEL_ERROR"
|
||||
"U_IDNA_ZERO_LENGTH_LABEL_ERROR",
|
||||
"U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR"
|
||||
};
|
||||
|
||||
U_CAPI const char * U_EXPORT2
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2003-2006, International Business Machines
|
||||
* Copyright (C) 2003-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -36,6 +36,7 @@ static void TestCompare(void);
|
|||
static void TestUnicode32Norm(void);
|
||||
static void TestJB4490(void);
|
||||
static void TestJB4475(void);
|
||||
static void TestLength(void);
|
||||
|
||||
void addIDNATest(TestNode** root);
|
||||
|
||||
|
@ -63,6 +64,7 @@ addIDNATest(TestNode** root)
|
|||
addTest(root, &TestUnicode32Norm,"idna/TestUnicode32Norm");
|
||||
addTest(root, &TestJB4490, "idna/TestJB4490");
|
||||
addTest(root, &TestJB4475, "idna/TestJB4475");
|
||||
addTest(root, &TestLength, "idna/TestLength");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -718,6 +720,96 @@ static void TestJB4475(){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestLength(){
|
||||
{
|
||||
static const char* cl = "my_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";
|
||||
UChar ul[128] = {'\0'};
|
||||
UChar dest[256] = {'\0'};
|
||||
int32_t destLen = LENGTHOF(dest);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError ps;
|
||||
int32_t len = (int32_t)strlen(cl);
|
||||
u_charsToUChars(cl, ul, len+1);
|
||||
destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
|
||||
log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
|
||||
log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
|
||||
log_err("uidna_toASCII failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
|
||||
log_err("uidna_toASCII failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
{
|
||||
static const char* cl = "my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.ibm.com";
|
||||
UChar ul[400] = {'\0'};
|
||||
UChar dest[400] = {'\0'};
|
||||
int32_t destLen = LENGTHOF(dest);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError ps;
|
||||
int32_t len = (int32_t)strlen(cl);
|
||||
u_charsToUChars(cl, ul, len+1);
|
||||
|
||||
destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
destLen = LENGTHOF(dest);
|
||||
len = -1;
|
||||
destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
uidna_compare(ul, len, ul, len, UIDNA_DEFAULT, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_compare failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
uidna_compare(ul, -1, ul, -1, UIDNA_DEFAULT, &status);
|
||||
if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
|
||||
log_err("uidna_compare failed with error %s.\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue