Debugger: Try harder to validate UTF-8.

When sending this in the websocket debugger, it needs to be valid utf-8 or
it will cause clients to abort the connection.  We want to reject invalid
utf-8 anyway.
This commit is contained in:
Unknown W. Brackets 2021-04-23 23:24:47 -07:00
parent f987c715aa
commit 56bcf04c49

View file

@ -64,13 +64,23 @@ bool IsLikelyStringAt(uint32_t addr) {
if (utf.end())
return false;
char verify[4];
while (!utf.end()) {
if (utf.invalid())
return false;
int pos = utf.byteIndex();
uint32_t c = utf.next();
int len = UTF8::encode(verify, c);
// Our decoder is a bit lax, so let's verify this is a normal encoding.
// This prevents us from trying to output invalid encodings in the debugger.
if (memcmp(p + pos, verify, len) != 0 || pos + len != utf.byteIndex())
return false;
if (c < ARRAY_SIZE(validControl) && !validControl[c])
return false;
if (c > 0x0010FFFF)
return false;
}
return true;