[gcc(refs/vendors/ibm/heads/gcc-9-branch)] Fix array index error in address_v6 comparisons

Peter Bergner bergner@gcc.gnu.org
Tue Feb 4 22:02:00 GMT 2020


https://gcc.gnu.org/g:38cb5876a2875703453d06d3eca5d976cd1414c0

commit 38cb5876a2875703453d06d3eca5d976cd1414c0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Oct 24 13:54:05 2019 +0100

    Fix array index error in address_v6 comparisons
    
    Backport from mainline
    2019-09-26  Jonathan Wakely  <jwakely@redhat.com>
    
    	* include/experimental/internet (operator==, operator<): Fix loop
    	condition to avoid reading past the end of the array.
    
    From-SVN: r277378

Diff:
---
 libstdc++-v3/ChangeLog                     | 6 ++++++
 libstdc++-v3/include/experimental/internet | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 518427d..92f91d6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,6 +1,12 @@
 2019-10-24  Jonathan Wakely  <jwakely@redhat.com>
 
 	Backport from mainline
+	2019-09-26  Jonathan Wakely  <jwakely@redhat.com>
+
+	* include/experimental/internet (operator==, operator<): Fix loop
+	condition to avoid reading past the end of the array.
+
+	Backport from mainline
 	2019-08-06  Jonathan Wakely  <jwakely@redhat.com>
 
 	P1651R0 bind_front should not unwrap reference_wrapper
diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet
index 467bdfd..e1368ec 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -539,7 +539,7 @@ namespace ip
     const auto& __aa = __a._M_bytes;
     const auto& __bb = __b._M_bytes;
     int __i = 0;
-    for (; __aa[__i] == __bb[__i] && __i < 16; ++__i)
+    for (; __i < 16 && __aa[__i] == __bb[__i]; ++__i)
       ;
     return __i == 16 ? __a.scope_id() == __b.scope_id() : false;
   }
@@ -554,7 +554,7 @@ namespace ip
     const auto& __aa = __a._M_bytes;
     const auto& __bb = __b._M_bytes;
     int __i = 0;
-    for (; __aa[__i] == __bb[__i] && __i < 16; ++__i)
+    for (; __i < 16 && __aa[__i] == __bb[__i]; ++__i)
       ;
     return __i == 16 ? __a.scope_id() < __b.scope_id() : __aa[__i] < __bb[__i];
   }



More information about the Libstdc++-cvs mailing list