summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shared/utf8.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/shared/utf8.c b/src/shared/utf8.c
index 9353559b76..8702ceb1b2 100644
--- a/src/shared/utf8.c
+++ b/src/shared/utf8.c
@@ -150,10 +150,12 @@ bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
int encoded_len, val;
encoded_len = utf8_encoded_valid_unichar((const char *) p);
- val = utf8_encoded_to_unichar((const char*) p);
-
if (encoded_len < 0 ||
- val < 0 ||
+ (size_t) encoded_len > length)
+ return false;
+
+ val = utf8_encoded_to_unichar((const char*) p);
+ if (val < 0 ||
is_unicode_control(val) ||
(!newline && val == '\n'))
return false;