diff --git a/icu4c/source/common/cstring.cpp b/icu4c/source/common/cstring.cpp index cc3f6deed890..9b8339de197b 100644 --- a/icu4c/source/common/cstring.cpp +++ b/icu4c/source/common/cstring.cpp @@ -329,12 +329,14 @@ uprv_strndup(const char *src, int32_t n) { if(n < 0) { dup = uprv_strdup(src); - } else { + } else if (n < INT32_MAX) { dup = (char*)uprv_malloc(n+1); if (dup) { uprv_memcpy(dup, src, n); dup[n] = 0; } + } else { + dup = nullptr; } return dup; diff --git a/icu4c/source/common/messagepattern.cpp b/icu4c/source/common/messagepattern.cpp index 96555ce8ae33..b51892255b78 100644 --- a/icu4c/source/common/messagepattern.cpp +++ b/icu4c/source/common/messagepattern.cpp @@ -1149,6 +1149,10 @@ MessagePattern::setParseError(UParseError *parseError, int32_t index) { if(parseError==nullptr) { return; } + if (msg.length() < index) { + U_ASSERT(msg.length() >= index); + return; + } parseError->offset=index; // Set preContext to some of msg before index. diff --git a/icu4c/source/common/ubidiln.cpp b/icu4c/source/common/ubidiln.cpp index 65e1212c7b26..eaa851e70d81 100644 --- a/icu4c/source/common/ubidiln.cpp +++ b/icu4c/source/common/ubidiln.cpp @@ -544,7 +544,7 @@ static int32_t getRunFromLogicalIndex(UBiDi *pBiDi, int32_t logicalIndex) { * negative number of BiDi control characters within this run. */ U_CFUNC UBool -ubidi_getRuns(UBiDi *pBiDi, UErrorCode*) { +ubidi_getRuns(UBiDi *pBiDi, UErrorCode* pErrorCode) { /* * This method returns immediately if the runs are already set. This * includes the case of length==0 (handled in setPara).. @@ -575,6 +575,10 @@ ubidi_getRuns(UBiDi *pBiDi, UErrorCode*) { * levels[]!=paraLevel but we have to treat it like it were so. */ limit=pBiDi->trailingWSStart; + if (limit <= 0) { + *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; + return false; + } /* count the runs, there is at least one non-WS run, and limit>0 */ runCount=0; for(i=0; i fMixedUnitCount) { U_ASSERT(micros.mixedMeasuresCount > 0); // Mixed unit: we must have more than one unit value + U_ASSERT(micros.mixedMeasuresCount <= fMixedUnitCount); status = U_UNSUPPORTED_ERROR; return µs.helpers.emptyWeakModifier; } diff --git a/icu4c/source/i18n/rbt_pars.cpp b/icu4c/source/i18n/rbt_pars.cpp index e2dbb058d5c5..927894532f37 100644 --- a/icu4c/source/i18n/rbt_pars.cpp +++ b/icu4c/source/i18n/rbt_pars.cpp @@ -1496,6 +1496,13 @@ int32_t TransliteratorParser::syntaxError(UErrorCode parseErrorCode, int32_t pos, UErrorCode& status) { + if (U_FAILURE(status)) { + return -1; + } + if (pos < 0 || pos > rule.length()) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return -1; + } parseError.offset = pos; parseError.line = 0 ; /* we are not using line numbers */ diff --git a/icu4c/source/i18n/rematch.cpp b/icu4c/source/i18n/rematch.cpp index cac4b0e271ec..e25e890dd9e9 100644 --- a/icu4c/source/i18n/rematch.cpp +++ b/icu4c/source/i18n/rematch.cpp @@ -4783,15 +4783,17 @@ void RegexMatcher::MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &statu UChar32 c; U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); - if (c < 256) { - Regex8BitSet &s8 = RegexStaticSets::gStaticSets->fPropSets8[opValue]; - if (s8.contains(c)) { - success = !success; - } - } else { - const UnicodeSet &s = RegexStaticSets::gStaticSets->fPropSets[opValue]; - if (s.contains(c)) { - success = !success; + if (c >= 0) { + if (c < 256) { + Regex8BitSet &s8 = RegexStaticSets::gStaticSets->fPropSets8[opValue]; + if (s8.contains(c)) { + success = !success; + } + } else { + const UnicodeSet &s = RegexStaticSets::gStaticSets->fPropSets[opValue]; + if (s.contains(c)) { + success = !success; + } } } if (!success) { @@ -4815,15 +4817,17 @@ void RegexMatcher::MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &statu UChar32 c; U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); - if (c < 256) { - Regex8BitSet &s8 = RegexStaticSets::gStaticSets->fPropSets8[opValue]; - if (s8.contains(c) == false) { - break; - } - } else { - const UnicodeSet &s = RegexStaticSets::gStaticSets->fPropSets[opValue]; - if (s.contains(c) == false) { - break; + if (c >= 0) { + if (c < 256) { + Regex8BitSet &s8 = RegexStaticSets::gStaticSets->fPropSets8[opValue]; + if (s8.contains(c) == false) { + break; + } + } else { + const UnicodeSet &s = RegexStaticSets::gStaticSets->fPropSets[opValue]; + if (s.contains(c) == false) { + break; + } } } fp = reinterpret_cast(fStack->popFrame(fFrameSize)); @@ -4844,20 +4848,21 @@ void RegexMatcher::MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &statu // There is input left. Pick up one char and test it for set membership. UChar32 c; U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); - if (c<256) { - Regex8BitSet *s8 = &fPattern->fSets8[opValue]; - if (s8->contains(c)) { - // The character is in the set. A Match. - break; - } - } else { - UnicodeSet* s = static_cast(fSets->elementAt(opValue)); - if (s->contains(c)) { - // The character is in the set. A Match. - break; + if (c >= 0) { + if (c<256) { + Regex8BitSet *s8 = &fPattern->fSets8[opValue]; + if (s8->contains(c)) { + // The character is in the set. A Match. + break; + } + } else { + UnicodeSet* s = static_cast(fSets->elementAt(opValue)); + if (s->contains(c)) { + // The character is in the set. A Match. + break; + } } } - // the character wasn't in the set. fp = reinterpret_cast(fStack->popFrame(fFrameSize)); } diff --git a/icu4c/source/i18n/simpletz.cpp b/icu4c/source/i18n/simpletz.cpp index 3f3b236ea45c..2d2a08e62683 100644 --- a/icu4c/source/i18n/simpletz.cpp +++ b/icu4c/source/i18n/simpletz.cpp @@ -1140,7 +1140,11 @@ SimpleTimeZone::initTransitionRules(UErrorCode& status) { } // Calculate the first DST start time - dstRule->getFirstStart(getRawOffset(), 0, firstDstStart); + if (!dstRule->getFirstStart(getRawOffset(), 0, firstDstStart)) { + status = U_ILLEGAL_ARGUMENT_ERROR; + deleteTransitionRules(); + return; + } // Create a TimeZoneRule for standard time timeRuleType = (endTimeMode == STANDARD_TIME) ? DateTimeRule::STANDARD_TIME : @@ -1178,7 +1182,11 @@ SimpleTimeZone::initTransitionRules(UErrorCode& status) { } // Calculate the first STD start time - stdRule->getFirstStart(getRawOffset(), dstRule->getDSTSavings(), firstStdStart); + if (!stdRule->getFirstStart(getRawOffset(), dstRule->getDSTSavings(), firstStdStart)) { + status = U_ILLEGAL_ARGUMENT_ERROR; + deleteTransitionRules(); + return; + } // Create a TimeZoneRule for initial time if (firstStdStart < firstDstStart) {