From 3264bbd19c600586ffd74ee18920bc99c5cde933 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 18 Nov 2024 23:46:10 +0100 Subject: [PATCH] wiretap: don't use void parameter type in wtap_new_ipv6_callback_t The wtap_new_ipv6_callback_t was initially introduced to allow add_new_ipv6 to be called from the wiretap library. It's first parameter is a 128-bit IPv6 address, so let's use that instead of a void pointer. This fixes an UBSan error that could cause a crash when CFI is enabled: wiretap/wtap.c:1623:4: runtime error: call to function add_ipv6_name through pointer to incorrect function type 'void (*)(const void *, const char *, bool)' Link: https://maskray.me/blog/2022-12-18-control-flow-integrity#fsanitizefunction --- capinfos.c | 2 +- wiretap/wtap.c | 2 +- wiretap/wtap.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/capinfos.c b/capinfos.c index af121e64e58..461616bb699 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1029,7 +1029,7 @@ count_ipv4_address(const unsigned int addr _U_, const char *name _U_, const bool } static void -count_ipv6_address(const void *addrp _U_, const char *name _U_, const bool static_entry _U_) +count_ipv6_address(const ws_in6_addr *addrp _U_, const char *name _U_, const bool static_entry _U_) { num_ipv6_addresses++; } diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 69056d98b6d..7557e7c83d3 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -1620,7 +1620,7 @@ wtapng_process_nrb_ipv6(wtap *wth, wtap_block_t nrb) if (wth->add_new_ipv6) { for (GList *elem = nrb_mand->ipv6_addr_list; elem != NULL; elem = elem->next) { hashipv6_t *tp = elem->data; - wth->add_new_ipv6(tp->addr, tp->name, false); + wth->add_new_ipv6((ws_in6_addr *)tp->addr, tp->name, false); } } } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 04a8067b486..220fc61785f 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1890,7 +1890,7 @@ typedef void (*wtap_new_ipv4_callback_t) (const unsigned addr, const char *name, WS_DLL_PUBLIC void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4); -typedef void (*wtap_new_ipv6_callback_t) (const void *addrp, const char *name, const bool static_entry); +typedef void (*wtap_new_ipv6_callback_t) (const ws_in6_addr *addrp, const char *name, const bool static_entry); WS_DLL_PUBLIC void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6);