This is an automated email from the ASF dual-hosted git repository.
eze pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/7.1.x by this push:
new 018ff84 This improves on #3008, making the code clearer
018ff84 is described below
commit 018ff84893c6bfec86bc5b548524cc51a824b1b4
Author: Leif Hedstrom <[email protected]>
AuthorDate: Wed Jan 9 09:46:41 2019 -0700
This improves on #3008, making the code clearer
(cherry picked from commit 571d11ecf49c410470e2efbc1eca469618629084)
---
proxy/http/HttpSM.cc | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 3e86697..962c5bb 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -4259,8 +4259,6 @@ HttpSM::parse_range_and_compare(MIMEField *field, int64_t
content_length)
const char *s, *e, *tmp;
RangeRecord *ranges = nullptr;
int64_t start, end;
- int64_t cutoff = INT64_MAX / 10;
- int64_t cutlim = INT64_MAX % 10;
ink_assert(field != nullptr && t_state.range_setup ==
HttpTransact::RANGE_NONE && t_state.ranges == nullptr);
@@ -4319,11 +4317,13 @@ HttpSM::parse_range_and_compare(MIMEField *field,
int64_t content_length)
for (start = 0; s < e && *s >= '0' && *s <= '9'; ++s) {
// check the int64 overflow in case of high gcc with O3 option
// thinking the start is always positive
- if (start >= cutoff && (start > cutoff || *s - '0' > cutlim)) {
+ int64_t new_start = start * 10 + (*s - '0');
+
+ if (new_start < start) { // Overflow
t_state.range_setup = HttpTransact::RANGE_NONE;
goto Lfaild;
}
- start = start * 10 + (*s - '0');
+ start = new_start;
}
// skip last white spaces
for (; s < e && ParseRules::is_ws(*s); ++s) {
@@ -4357,11 +4357,13 @@ HttpSM::parse_range_and_compare(MIMEField *field,
int64_t content_length)
for (end = 0; s < e && *s >= '0' && *s <= '9'; ++s) {
// check the int64 overflow in case of high gcc with O3 option
// thinking the start is always positive
- if (end >= cutoff && (end > cutoff || *s - '0' > cutlim)) {
+ int64_t new_end = end * 10 + (*s - '0');
+
+ if (new_end < end) { // Overflow
t_state.range_setup = HttpTransact::RANGE_NONE;
goto Lfaild;
}
- end = end * 10 + (*s - '0');
+ end = new_end;
}
// skip last white spaces
for (; s < e && ParseRules::is_ws(*s); ++s) {