From a45bac77fe41dbc91ab4f16bce463f3c90a80ca8 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Fri, 4 Sep 2015 23:45:19 +0000 Subject: [PATCH] ICU-11765 fix utrans_stripRules() source overruns from a comment or an escape at the end of the source string; make U8_SET_CP_LIMIT() work with index after NUL terminator, consistent with U16_SET_CP_LIMIT(), although strictly speaking this behavior is undefined X-SVN-Rev: 37889 --- icu4c/source/common/unicode/utf8.h | 4 ++-- icu4c/source/i18n/rbt_pars.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/unicode/utf8.h b/icu4c/source/common/unicode/utf8.h index 7bd0b0e8526..1198a17331b 100644 --- a/icu4c/source/common/unicode/utf8.h +++ b/icu4c/source/common/unicode/utf8.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2014, International Business Machines +* Copyright (C) 1999-2015, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -815,7 +815,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); * @stable ICU 2.4 */ #define U8_SET_CP_LIMIT(s, start, i, length) { \ - if((start)<(i) && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \ + if((start)<(i) && ((i)<(length) || (length)<0)) { \ U8_BACK_1(s, start, i); \ U8_FWD_1(s, i, length); \ } \ diff --git a/icu4c/source/i18n/rbt_pars.cpp b/icu4c/source/i18n/rbt_pars.cpp index cebbe2ac749..fadc3d21b24 100644 --- a/icu4c/source/i18n/rbt_pars.cpp +++ b/icu4c/source/i18n/rbt_pars.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (C) 1999-2014, International Business Machines + * Copyright (C) 1999-2015, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -1674,11 +1674,18 @@ utrans_stripRules(const UChar *source, int32_t sourceLen, UChar *target, UErrorC target--; } do { + if (source == sourceLimit) { + c = U_SENTINEL; + break; + } c = *(source++); } while (c != CR && c != LF); + if (c < 0) { + break; + } } - else if (c == ESCAPE) { + else if (c == ESCAPE && source < sourceLimit) { UChar32 c2 = *source; if (c2 == CR || c2 == LF) { /* A backslash at the end of a line. */ -- 2.40.0