From e5d9ad2f0bc007089394ceb2bdf9847887d671bc Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 16 Sep 2023 17:22:33 +0900 Subject: [PATCH] Fix test errors with ubsan --- src/BitfieldMan.cc | 2 +- src/cookie_helper.cc | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index bb8e2882..43d3ba25 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -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_); diff --git a/src/cookie_helper.cc b/src/cookie_helper.cc index 0e546109..8ad1e518 100644 --- a/src/cookie_helper.cc +++ b/src/cookie_helper.cc @@ -300,12 +300,18 @@ std::unique_ptr parse(const std::string& cookieStr, } else { int64_t n = creationTime; - n += delta; - if (n < 0 || std::numeric_limits::max() < n) { - maxAge = std::numeric_limits::max(); - } - else { - maxAge = n; + + if (n > std::numeric_limits::max() - delta) { + maxAge = std::numeric_limits::max(); + } else { + n += delta; + + if (n < 0 || std::numeric_limits::max() < n) { + maxAge = std::numeric_limits::max(); + } + else { + maxAge = n; + } } } }