You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/02/12 00:42:58 UTC

[trafficserver] 04/05: This improves on #3008, making the code clearer

This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit a8d6a1722e0227f5dab0775b81a0e6323c50d592
Author: Leif Hedstrom <zw...@apache.org>
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 8d434d8..b6d03b5 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -4170,8 +4170,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);
 
@@ -4230,11 +4228,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) {
@@ -4268,11 +4268,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) {