Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion icu4c/source/common/cstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions icu4c/source/common/messagepattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion icu4c/source/common/ubidiln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)..
Expand Down Expand Up @@ -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<limit; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion icu4c/source/i18n/number_longnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,9 @@ void MixedUnitLongNameHandler::processQuantity(DecimalQuantity &quantity, MicroP
const Modifier *MixedUnitLongNameHandler::getMixedUnitModifier(DecimalQuantity &quantity,
MicroProps &micros,
UErrorCode &status) const {
if (micros.mixedMeasuresCount == 0) {
if (micros.mixedMeasuresCount == 0 || micros.mixedMeasuresCount > 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 &micros.helpers.emptyWeakModifier;
}
Expand Down
7 changes: 7 additions & 0 deletions icu4c/source/i18n/rbt_pars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
65 changes: 35 additions & 30 deletions icu4c/source/i18n/rematch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<REStackFrame*>(fStack->popFrame(fFrameSize));
Expand All @@ -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<UnicodeSet*>(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<UnicodeSet*>(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<REStackFrame*>(fStack->popFrame(fFrameSize));
}
Expand Down
12 changes: 10 additions & 2 deletions icu4c/source/i18n/simpletz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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) {
Expand Down