Add a log domain for encoding errors and lower the log level

Using a warning is probably too exalted for the current state
of the code, where UTF-8 errors are somewhat expected from
dissectors that are lax about input validation.

Use a debug level with its own "UTF-8" domain instead.

Using a dedicated domain allows to filter on encoding errors and
with some enhancements to the logging subsystem make them fatal
for tracking and debugging purposes.

Using a dedicated domain might have other drawbacks but for now
it seems like the best approach.
This commit is contained in:
João Valverde 2022-09-27 22:16:21 +01:00
parent feb7f45179
commit 32befe119d
3 changed files with 6 additions and 2 deletions

View File

@ -21,7 +21,8 @@ static inline void
string_validate_utf8(fvalue_t *fv)
{
if (wmem_strbuf_sanitize_utf8(fv->value.strbuf)) {
ws_warning("String fvalues must use a valid UTF-8 encoding."
ws_log_full(LOG_DOMAIN_UTF_8, LOG_LEVEL_DEBUG, __FILE__, -1, __func__,
"String fvalues must use a valid UTF-8 encoding."
" This string has been sanitized to look like this: %s",
wmem_strbuf_get_str(fv->value.strbuf));
}

View File

@ -497,7 +497,8 @@ format_text_internal(wmem_allocator_t *allocator,
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);
ws_log_full(LOG_DOMAIN_UTF_8, LOG_LEVEL_DEBUG, __FILE__, -1, __func__,
"String argument contained UTF-8 errors: %s", fmtbuf);
}
return fmtbuf;
}

View File

@ -42,6 +42,8 @@
#define LOG_DOMAIN_EXTCAP "Extcap"
#define LOG_DOMAIN_UTF_8 "UTF-8"
/*
* Ascending order by priority needs to be maintained. Higher priorities have
* higher values.