From 912c9c22545e3ed9020da8cb0088f230136c262e Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 22 Feb 2021 07:38:59 -0800 Subject: [PATCH] fix: cap sendInputEvent text length at n-1 (#27827) --- shell/common/gin_converters/blink_converter.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/common/gin_converters/blink_converter.cc b/shell/common/gin_converters/blink_converter.cc index b80c8eae1a..c7cfb3a6be 100644 --- a/shell/common/gin_converters/blink_converter.cc +++ b/shell/common/gin_converters/blink_converter.cc @@ -209,9 +209,9 @@ bool Converter::FromV8(v8::Isolate* isolate, size_t text_length_cap = blink::WebKeyboardEvent::kTextLengthCap; base::string16 text16 = base::UTF8ToUTF16(str); - memset(out->text, 0, text_length_cap); - memset(out->unmodified_text, 0, text_length_cap); - for (size_t i = 0; i < std::min(text_length_cap, text16.size()); ++i) { + std::fill_n(out->text, text_length_cap, 0); + std::fill_n(out->unmodified_text, text_length_cap, 0); + for (size_t i = 0; i < std::min(text_length_cap - 1, text16.size()); ++i) { out->text[i] = text16[i]; out->unmodified_text[i] = text16[i]; }