Skip to content

Commit

Permalink
wiretap: don't use void parameter type in wtap_new_ipv6_callback_t
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lekensteyn authored and guyharris committed Nov 21, 2024
1 parent 43df2a3 commit 3264bbd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion wiretap/wtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion wiretap/wtap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3264bbd

Please sign in to comment.