diff options
| author | Tatsuhiro Tsujikawa <404610+tatsuhiro-t@users.noreply.github.com> | 2023-09-16 17:45:35 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-16 17:45:35 +0900 |
| commit | dbbd1bfbf97548d773e3e7954e6819880ef6bd57 (patch) | |
| tree | ea910d9511bae81cf16ee29dd7fdeff6b7f16eb3 | |
| parent | dfdbc22b239311e13facdca926db0aeab9ce28e6 (diff) | |
| parent | e5d9ad2f0bc007089394ceb2bdf9847887d671bc (diff) | |
Merge pull request #2095 from aria2/fix-undefined
Fix test errors with ubsan
| -rw-r--r-- | src/BitfieldMan.cc | 2 | ||||
| -rw-r--r-- | 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<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; + } } } } |
