epan: Add a warning for invalid UTF-8 with format_text()
This commit is contained in:
parent
6d06d4e46b
commit
621257f472
|
@ -200,6 +200,7 @@ format_text_internal(wmem_allocator_t *allocator,
|
||||||
FMTBUF_VARS;
|
FMTBUF_VARS;
|
||||||
const guchar *stringend = string + len;
|
const guchar *stringend = string + len;
|
||||||
guchar c;
|
guchar c;
|
||||||
|
bool is_valid_utf8 = true;
|
||||||
|
|
||||||
while (string < stringend) {
|
while (string < stringend) {
|
||||||
/*
|
/*
|
||||||
|
@ -350,6 +351,11 @@ format_text_internal(wmem_allocator_t *allocator,
|
||||||
uc = UNREPL;
|
uc = UNREPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uc == UNREPL) {
|
||||||
|
/* Flag this UTF-8 string as having been sanitized. */
|
||||||
|
is_valid_utf8 = false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* OK, is it a printable Unicode character?
|
* OK, is it a printable Unicode character?
|
||||||
*/
|
*/
|
||||||
|
@ -487,6 +493,12 @@ format_text_internal(wmem_allocator_t *allocator,
|
||||||
}
|
}
|
||||||
|
|
||||||
FMTBUF_ENDSTR;
|
FMTBUF_ENDSTR;
|
||||||
|
|
||||||
|
if (!is_valid_utf8) {
|
||||||
|
/* This function expects valid UTF-8 as input. The extra validation performed is a safeguard.
|
||||||
|
* In a brighter future it may be removed. Emit a warning and display the sanitized string. */
|
||||||
|
ws_warning("String argument contained UTF-8 errors: %s", fmtbuf);
|
||||||
|
}
|
||||||
return fmtbuf;
|
return fmtbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue