hscollider: fix input length for UTF8 check

This commit is contained in:
Wang, Xiang W
2018-04-17 23:26:04 -04:00
committed by Chang, Harry
parent f877f14641
commit 08b00f6149
5 changed files with 8 additions and 6 deletions

View File

@@ -118,7 +118,8 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression,
expr.utf8 = mode.utf8; /* utf8 may be set by parse() */
if (expr.utf8 && !isValidUtf8(expression)) {
const size_t len = strlen(expression);
if (expr.utf8 && !isValidUtf8(expression, len)) {
throw ParseError("Expression is not valid UTF-8.");
}

View File

@@ -60,12 +60,11 @@ bool isAllowedCodepoint(u32 val) {
return true;
}
bool isValidUtf8(const char *expression) {
bool isValidUtf8(const char *expression, const size_t len) {
if (!expression) {
return true;
}
const size_t len = strlen(expression);
const u8 *s = (const u8 *)expression;
u32 val;

View File

@@ -29,10 +29,12 @@
#ifndef PARSER_UTF8_VALIDATE_H
#define PARSER_UTF8_VALIDATE_H
#include <cstddef> // size_t
namespace ue2 {
/** \brief Validate that the given expression is well-formed UTF-8. */
bool isValidUtf8(const char *expression);
bool isValidUtf8(const char *expression, const size_t len);
} // namespace ue2