summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2023-09-16 17:22:33 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2023-09-16 17:22:33 +0900
commite5d9ad2f0bc007089394ceb2bdf9847887d671bc (patch)
treeea910d9511bae81cf16ee29dd7fdeff6b7f16eb3
parentdfdbc22b239311e13facdca926db0aeab9ce28e6 (diff)
Fix test errors with ubsan
-rw-r--r--src/BitfieldMan.cc2
-rw-r--r--src/cookie_helper.cc18
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<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;
+ }
}
}
}