From a856eb2eba3be79ebc7cede81cc0a89a21580c1b Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Thu, 19 Feb 2009 05:18:34 +0000 Subject: [PATCH] ICU-6677 add and fix u_strFromUTF32() input string validation X-SVN-Rev: 25441 --- icu4c/source/common/ustrtrns.c | 125 ++++++++++++++------------ icu4c/source/test/cintltst/custrtrn.c | 78 ++++++++++++++++ 2 files changed, 145 insertions(+), 58 deletions(-) diff --git a/icu4c/source/common/ustrtrns.c b/icu4c/source/common/ustrtrns.c index 5f013c1006..a5c2334b93 100644 --- a/icu4c/source/common/ustrtrns.c +++ b/icu4c/source/common/ustrtrns.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 2001-2007, International Business Machines +* Copyright (C) 2001-2009, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -36,78 +36,87 @@ u_strFromUTF32(UChar *dest, int32_t *pDestLength, const UChar32 *src, int32_t srcLength, - UErrorCode *pErrorCode) -{ - int32_t reqLength = 0; - uint32_t ch =0; - UChar *pDestLimit =dest+destCapacity; - UChar *pDest = dest; - const uint32_t *pSrc = (const uint32_t *)src; + UErrorCode *pErrorCode) { + const UChar32 *srcLimit; + UChar32 ch; + UChar *destLimit; + UChar *pDest; + int32_t reqLength; /* args check */ - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)){ + if(U_FAILURE(*pErrorCode)){ return NULL; } - if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } - /* Check if the source is null terminated */ - if(srcLength == -1 ){ - while(((ch=*pSrc)!=0) && (pDest < pDestLimit)){ - ++pSrc; - if(ch<=0xFFFF){ - *(pDest++)=(UChar)ch; - }else if(ch<=0x10ffff){ - *(pDest++)=UTF16_LEAD(ch); - if(pDest