From cf94032b2e5d4dc662f1f1573b0b7a896194901b Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Tue, 10 Apr 2018 16:05:35 +0200
Subject: [PATCH] Fixed possible string over-indexing in is_utf8 function

Change-Id: I901e88cc6ff5bf0424a98dab62954d3fce95aaf0
Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
---
 compiler2/PredefFunc.cc | 2 +-
 core/Addfunc.cc         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler2/PredefFunc.cc b/compiler2/PredefFunc.cc
index 04230343f..07a2dc7e8 100644
--- a/compiler2/PredefFunc.cc
+++ b/compiler2/PredefFunc.cc
@@ -818,7 +818,7 @@ static CharCoding::CharCodingType is_utf8(size_t length, const unsigned char* st
       // the second and third (and so on) UTF-8 byte looks like 10xx xxxx      
       while (0 < noofUTF8 ) {
         ++i;
-        if (!(strptr[i] & MSB) || (strptr[i] & MSBmin1) || i >= length) { // if not like this: 10xx xxxx
+        if (i >= length || !(strptr[i] & MSB) || (strptr[i] & MSBmin1)) { // if not like this: 10xx xxxx
           return CharCoding::UNKNOWN;
         }
         --noofUTF8;
diff --git a/core/Addfunc.cc b/core/Addfunc.cc
index c41f59b49..651cfeed2 100644
--- a/core/Addfunc.cc
+++ b/core/Addfunc.cc
@@ -239,7 +239,7 @@ static CharCoding::CharCodingType is_utf8 ( const OCTETSTRING& ostr )
       while (0 < noofUTF8 ) {
         ++i;
   //std::cout << "mask & strptr[" << i << "] " << std::hex << (int)strptr[i]  << std::endl;
-        if (!(strptr[i] & MSB) || (strptr[i] & MSBmin1) || i >= ostr.lengthof()) { // if not like this: 10xx xxxx
+        if (i >= ostr.lengthof() || !(strptr[i] & MSB) || (strptr[i] & MSBmin1)) { // if not like this: 10xx xxxx
           return CharCoding::UNKNOWN;
         }
         --noofUTF8;
-- 
GitLab