From: Tom Peters (thopeter) Date: Fri, 16 Jun 2017 19:20:34 +0000 (-0400) Subject: Merge pull request #919 in SNORT/snort3 from Bug203817 to master X-Git-Tag: 3.0.0-239~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=425154aab0eab4e7e7e9b0dafb710a37d2f9e1dd;p=thirdparty%2Fsnort3.git Merge pull request #919 in SNORT/snort3 from Bug203817 to master Squashed commit of the following: commit 070e1a8857475b77e22809303caa66a9b3a07eba Author: allewi Date: Thu Jun 1 12:40:04 2017 -0400 adding changes for bug203817 --- diff --git a/src/service_inspectors/http_inspect/http_msg_body.cc b/src/service_inspectors/http_inspect/http_msg_body.cc index 988db4ff8..aa16929fd 100644 --- a/src/service_inspectors/http_inspect/http_msg_body.cc +++ b/src/service_inspectors/http_inspect/http_msg_body.cc @@ -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; diff --git a/src/utils/util_utf.cc b/src/utils/util_utf.cc index 0ccd40286..791ac619e 100644 --- a/src/utils/util_utf.cc +++ b/src/utils/util_utf.cc @@ -25,6 +25,7 @@ #include "util_utf.h" +#include #include #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; diff --git a/src/utils/util_utf.h b/src/utils/util_utf.h index e14269aca..1c0781306 100644 --- a/src/utils/util_utf.h +++ b/src/utils/util_utf.h @@ -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