wiretap: Fix pcapng UTF-8 validation

g_utf_8_make_valid() replaces embedded NULs with unicode
replacement characters and this behaviour does not match
the pcapng spec; the first NULL should terminate the string
instead.

Use ws_utf8_make_valid() which provides the correct behaviour.
This commit is contained in:
João Valverde 2023-02-06 04:31:31 +00:00
parent 9feb85ce4d
commit 7a33d04056
1 changed files with 2 additions and 4 deletions

View File

@ -28,6 +28,7 @@
#include <wsutil/glib-compat.h>
#include <wsutil/ws_assert.h>
#include <wsutil/ws_roundup.h>
#include <wsutil/unicode-utils.h>
#include "wtap-int.h"
#include "file_wrappers.h"
@ -761,10 +762,7 @@ pcapng_process_string_option(wtapng_block_t *wblock, guint16 option_code,
char *str;
/* Validate UTF-8 encoding. */
if (g_utf8_validate(opt, optlen, NULL))
str = g_strndup(opt, optlen);
else
str = g_utf8_make_valid(opt, optlen);
str = ws_utf8_make_valid(NULL, opt, optlen);
wtap_block_add_string_option_owned(wblock->block, option_code, str);
}