]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #919 in SNORT/snort3 from Bug203817 to master
authorTom Peters (thopeter) <thopeter@cisco.com>
Fri, 16 Jun 2017 19:20:34 +0000 (15:20 -0400)
committerTom Peters (thopeter) <thopeter@cisco.com>
Fri, 16 Jun 2017 19:20:34 +0000 (15:20 -0400)
Squashed commit of the following:

commit 070e1a8857475b77e22809303caa66a9b3a07eba
Author: allewi <allewi@cisco.com>
Date:   Thu Jun 1 12:40:04 2017 -0400

    adding changes for bug203817

src/service_inspectors/http_inspect/http_msg_body.cc
src/utils/util_utf.cc
src/utils/util_utf.h

index 988db4ff8dfb4dcff93166da44a3c9c537ecbdef..aa16929fdce0fecf026a41523ed6704eebc758ba 100644 (file)
@@ -79,8 +79,9 @@ void HttpMsgBody::do_utf_decoding(const Field& input, Field& output)
         int bytes_copied;
         bool decoded;
         uint8_t* buffer = new uint8_t[input.length()];
-        decoded = session_data->utf_state->decode_utf((const char*)input.start(), input.length(),
-                            (char*)buffer, input.length(), &bytes_copied);
+        decoded = session_data->utf_state->decode_utf(
+            input.start(), input.length(), buffer, input.length(), &bytes_copied);
+
         if (!decoded)
         {
             delete[] buffer;
index 0ccd40286e5fc88a191b744794110f918c523b5e..791ac619e12879a6b1e5b46ee7843b5373aa52f5 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "util_utf.h"
 
+#include <cassert>
 #include <cstring>
 
 #define DSTATE_FIRST 0
@@ -77,11 +78,11 @@ bool UtfDecodeSession::is_utf_encoding_present()
  * returns: true or false
  */
 
-bool UtfDecodeSession::DecodeUTF16LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF16LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
     int* bytes_copied)
 {
-    const char* src_index = src;
-    char* dst_index = dst;
+    const uint8_t* src_index = src;
+    uint8_t* dst_index = dst;
     bool result = true;
 
     while ((src_index < (src + src_len)) &&
@@ -95,12 +96,12 @@ bool UtfDecodeSession::DecodeUTF16LE(const char* src, unsigned int src_len, char
             dstate.state = DSTATE_SECOND;
             break;
         case DSTATE_SECOND:
-            if (*src_index++ > 0)
+            if (*src_index++ != 0)
                 result = false;
             dstate.state = DSTATE_FIRST;
             break;
         default:
-            return false;
+            assert(false);
         }
     }
 
@@ -120,11 +121,11 @@ bool UtfDecodeSession::DecodeUTF16LE(const char* src, unsigned int src_len, char
  * returns: true or false
  */
 
-bool UtfDecodeSession::DecodeUTF16BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF16BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
     int* bytes_copied)
 {
-    const char* src_index = src;
-    char* dst_index = dst;
+    const uint8_t* src_index = src;
+    uint8_t* dst_index = dst;
     bool result = true;
 
     while ((src_index < (src + src_len)) &&
@@ -134,7 +135,7 @@ bool UtfDecodeSession::DecodeUTF16BE(const char* src, unsigned int src_len, char
         switch (dstate.state)
         {
         case DSTATE_FIRST:
-            if (*src_index++ > 0)
+            if (*src_index++ != 0)
                 result = false;
             dstate.state = DSTATE_SECOND;
             break;
@@ -143,7 +144,7 @@ bool UtfDecodeSession::DecodeUTF16BE(const char* src, unsigned int src_len, char
             dstate.state = DSTATE_FIRST;
             break;
         default:
-            return false;
+            assert(false);
         }
     }
 
@@ -163,11 +164,11 @@ bool UtfDecodeSession::DecodeUTF16BE(const char* src, unsigned int src_len, char
  * returns: true or false
  */
 
-bool UtfDecodeSession::DecodeUTF32LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF32LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
     int* bytes_copied)
 {
-    const char* src_index = src;
-    char* dst_index = dst;
+    const uint8_t* src_index = src;
+    uint8_t* dst_index = dst;
     bool result = true;
 
     while ((src_index < (src + src_len)) &&
@@ -183,7 +184,7 @@ bool UtfDecodeSession::DecodeUTF32LE(const char* src, unsigned int src_len, char
         case DSTATE_SECOND:
         case DSTATE_THIRD:
         case DSTATE_FOURTH:
-            if (*src_index++ > 0)
+            if (*src_index++ != 0)
                 result = false;
             if (dstate.state == DSTATE_FOURTH)
                 dstate.state = DSTATE_FIRST;
@@ -191,7 +192,7 @@ bool UtfDecodeSession::DecodeUTF32LE(const char* src, unsigned int src_len, char
                 dstate.state++;
             break;
         default:
-            return false;
+            assert(false);
         }
     }
 
@@ -211,11 +212,11 @@ bool UtfDecodeSession::DecodeUTF32LE(const char* src, unsigned int src_len, char
  * returns: true or false
  */
 
-bool UtfDecodeSession::DecodeUTF32BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF32BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
     int* bytes_copied)
 {
-    const char* src_index = src;
-    char* dst_index = dst;
+    const uint8_t* src_index = src;
+    uint8_t* dst_index = dst;
     bool result = true;
 
     while ((src_index < (src + src_len)) &&
@@ -227,7 +228,7 @@ bool UtfDecodeSession::DecodeUTF32BE(const char* src, unsigned int src_len, char
         case DSTATE_FIRST:
         case DSTATE_SECOND:
         case DSTATE_THIRD:
-            if (*src_index++ > 0)
+            if (*src_index++ != 0)
                 result = false;
             dstate.state++;
             break;
@@ -236,7 +237,7 @@ bool UtfDecodeSession::DecodeUTF32BE(const char* src, unsigned int src_len, char
             dstate.state = DSTATE_FIRST;
             break;
         default:
-            return false;
+            assert(false);
         }
     }
 
@@ -245,7 +246,7 @@ bool UtfDecodeSession::DecodeUTF32BE(const char* src, unsigned int src_len, char
     return result;
 }
 
-void UtfDecodeSession::determine_charset(const char** src, unsigned int *src_len)
+void UtfDecodeSession::determine_charset(const uint8_t** src, unsigned int *src_len)
 {
     CharsetCode charset;
     if (dstate.charset == CHARSET_UNKNOWN)
@@ -323,7 +324,7 @@ void UtfDecodeSession::determine_charset(const char** src, unsigned int *src_len
 
 /* Wrapper function for DecodeUTF{16,32}{LE,BE} */
 bool UtfDecodeSession::decode_utf(
-    const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied)
+    const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied)
 {
     *bytes_copied = 0;
 
index e14269aca21e5357d88787bb7e64def0eade01be..1c07813067e6b5ce8d72fc67b4a2b67df776eabf 100644 (file)
@@ -58,13 +58,13 @@ public:
     void set_decode_utf_state_charset(CharsetCode charset);
     CharsetCode get_decode_utf_state_charset();
     bool is_utf_encoding_present();
-    bool decode_utf(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
+    bool decode_utf(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
 private:
     decode_utf_state_t dstate;
-    bool DecodeUTF16LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
-    bool DecodeUTF16BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
-    bool DecodeUTF32LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
-    bool DecodeUTF32BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
-    void determine_charset(const char** src, unsigned int *src_len);
+    bool DecodeUTF16LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+    bool DecodeUTF16BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+    bool DecodeUTF32LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+    bool DecodeUTF32BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+    void determine_charset(const uint8_t** src, unsigned int *src_len);
 };
 #endif