diff --git a/lib/utf8_mosq.c b/lib/utf8_mosq.c index f20e9931..dd5eedd9 100644 --- a/lib/utf8_mosq.c +++ b/lib/utf8_mosq.c @@ -60,11 +60,11 @@ int mosquitto_validate_utf8(const char *str, int len) } /* Reconstruct full code point */ + if(i == len-codelen+1){ + /* Not enough data */ + return MOSQ_ERR_MALFORMED_UTF8; + } for(j=0; j 0x10FFFF)){ return MOSQ_ERR_MALFORMED_UTF8; } } diff --git a/test/lib/c/09-util-utf8-validate.c b/test/lib/c/09-util-utf8-validate.c index 1a472328..8a8e85b4 100644 --- a/test/lib/c/09-util-utf8-validate.c +++ b/test/lib/c/09-util-utf8-validate.c @@ -53,7 +53,8 @@ int main(int argc, char *argv[]) assert_valid("2.3.2 U-0000E000 = ee 80 80 = \"\""); assert_valid("2.3.3 U-0000FFFD = ef bf bd = \"�\""); assert_valid("2.3.4 U-0010FFFF = f4 8f bf bf = \"􏿿\""); - assert_valid("2.3.5 U-00110000 = f4 90 80 80 = \"\""); + /* This used to be valid in pre-2003 utf-8 */ + assert_invalid("2.3.5 U-00110000 = f4 90 80 80 = \"\""); /* 3 Malformed sequences */ /* 3.1 Unexpected continuation bytes */ diff --git a/test/lib/cpp/09-util-utf8-validate.cpp b/test/lib/cpp/09-util-utf8-validate.cpp index ea8c0218..2decafcb 100644 --- a/test/lib/cpp/09-util-utf8-validate.cpp +++ b/test/lib/cpp/09-util-utf8-validate.cpp @@ -53,7 +53,8 @@ int main(int argc, char *argv[]) assert_valid("2.3.2 U-0000E000 = ee 80 80 = \"\""); assert_valid("2.3.3 U-0000FFFD = ef bf bd = \"�\""); assert_valid("2.3.4 U-0010FFFF = f4 8f bf bf = \"􏿿\""); - assert_valid("2.3.5 U-00110000 = f4 90 80 80 = \"\""); + /* This used to be valid in pre-2003 utf-8 */ + assert_invalid("2.3.5 U-00110000 = f4 90 80 80 = \"\""); /* 3 Malformed sequences */ /* 3.1 Unexpected continuation bytes */