aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2023-02-06 04:31:31 +0000
committerJoão Valverde <j@v6e.pt>2023-02-06 15:03:49 +0000
commit7a33d04056ff5926bd4c7adf82613de07592f9e0 (patch)
treee6a3b572359a287423bc71b57f177ae89bafecf3
parent9feb85ce4db95ad86efe5c00fbbaee230e289f09 (diff)
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.
-rw-r--r--wiretap/pcapng.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index 98bc2375aa..6cd40f2564 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -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);
}