Problem using "WireGuardSetConfiguration" for Wireguard-NT with heap allocated configuration

Jason A. Donenfeld Jason at
Fri Aug 13 22:19:55 UTC 2021

Hi Lukas,

This appears to be a C pointer snafu, with this line in the code you sent:

> if (!WireGuardSetConfiguration(Adapter, (WIREGUARD_INTERFACE*)&(buffer), sizeof(struct t))) {

The issue is that `buffer` is already a pointer to the malloc'd
memory, so passing &buffer is actually the address of the pointer that
points to the memory you want. The reason why the example.c code
passes "&thing" and not "thing" is because thing is on the stack. But
in your case, `buffer` is on the heap, so it's already a pointer. The
second thing that stands out is `sizeof(struct t)` might not be what
you want. Instead try providing as length the same length that you
passed to the malloc call -- sizeof(iface)+sizeof(peer).

Hope that helps.


More information about the WireGuard mailing list