Browse Source

Fix test errors with ubsan

Tatsuhiro Tsujikawa 2 years ago
parent
commit
e5d9ad2f0b
2 changed files with 13 additions and 7 deletions
  1. 1 1
      src/BitfieldMan.cc
  2. 12 6
      src/cookie_helper.cc

+ 1 - 1
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_);

+ 12 - 6
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;
+            }
           }
         }
       }