Merge pull request #2095 from aria2/fix-undefined

Fix test errors with ubsan
pull/2096/head
Tatsuhiro Tsujikawa 2023-09-16 17:45:35 +09:00 committed by GitHub
commit dbbd1bfbf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -662,7 +662,7 @@ bool BitfieldMan::isUseBitSet(size_t index) const
void BitfieldMan::setBitfield(const unsigned char* bitfield,
size_t bitfieldLength)
{
if (bitfieldLength_ != bitfieldLength) {
if (bitfieldLength_ == 0 || bitfieldLength_ != bitfieldLength) {
return;
}
memcpy(bitfield_, bitfield, bitfieldLength_);

View File

@ -300,12 +300,18 @@ std::unique_ptr<Cookie> parse(const std::string& cookieStr,
}
else {
int64_t n = creationTime;
n += delta;
if (n < 0 || std::numeric_limits<time_t>::max() < n) {
maxAge = std::numeric_limits<time_t>::max();
}
else {
maxAge = n;
if (n > std::numeric_limits<int64_t>::max() - delta) {
maxAge = std::numeric_limits<int64_t>::max();
} else {
n += delta;
if (n < 0 || std::numeric_limits<time_t>::max() < n) {
maxAge = std::numeric_limits<time_t>::max();
}
else {
maxAge = n;
}
}
}
}