Fix test errors with ubsan

This commit is contained in:
Tatsuhiro Tsujikawa 2023-09-16 17:22:33 +09:00
parent dfdbc22b23
commit e5d9ad2f0b
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;
}
}
}
}