mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-08-01 17:12:50 +02:00
fix: awg memory management
Some checks are pending
Linux / Build for Ubuntu (push) Waiting to run
Linux / Build for Alpine (push) Waiting to run
Linux / GitHub Release (push) Blocked by required conditions
Windows / Build for Windows (push) Waiting to run
Windows / GitHub Release (push) Blocked by required conditions
Some checks are pending
Linux / Build for Ubuntu (push) Waiting to run
Linux / Build for Alpine (push) Waiting to run
Linux / GitHub Release (push) Blocked by required conditions
Windows / Build for Windows (push) Waiting to run
Windows / GitHub Release (push) Blocked by required conditions
This commit is contained in:
parent
430e39aaf9
commit
3a610feb96
5 changed files with 67 additions and 12 deletions
|
@ -150,6 +150,21 @@ static inline void free_wgdevice(struct wgdevice *dev)
|
|||
free(allowedip);
|
||||
free(peer);
|
||||
}
|
||||
|
||||
|
||||
free(dev->init_packet_magic_header);
|
||||
free(dev->response_packet_magic_header);
|
||||
free(dev->underload_packet_magic_header);
|
||||
free(dev->transport_packet_magic_header);
|
||||
free(dev->i1);
|
||||
free(dev->i2);
|
||||
free(dev->i3);
|
||||
free(dev->i4);
|
||||
free(dev->i5);
|
||||
free(dev->j1);
|
||||
free(dev->j2);
|
||||
free(dev->j3);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
|
|||
dev->flags |= WGDEVICE_HAS_S4;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_number(nvl_device, "h1")) {
|
||||
if (nvlist_exists_binary(nvl_device, "h1")) {
|
||||
binary = nvlist_get_binary(nvl_device, "h1", &size);
|
||||
if (binary && size < MAX_AWG_STRING_LEN)
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
|
|||
dev->flags |= WGDEVICE_HAS_H1;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_number(nvl_device, "h2")) {
|
||||
if (nvlist_exists_binary(nvl_device, "h2")) {
|
||||
binary = nvlist_get_binary(nvl_device, "h2", &size);
|
||||
if (binary && size < MAX_AWG_STRING_LEN)
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
|
|||
dev->flags |= WGDEVICE_HAS_H2;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_number(nvl_device, "h3")) {
|
||||
if (nvlist_exists_binary(nvl_device, "h3")) {
|
||||
binary = nvlist_get_binary(nvl_device, "h3", &size);
|
||||
if (binary && size < MAX_AWG_STRING_LEN)
|
||||
{
|
||||
|
@ -164,7 +164,7 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
|
|||
dev->flags |= WGDEVICE_HAS_H3;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_number(nvl_device, "h4")) {
|
||||
if (nvlist_exists_binary(nvl_device, "h4")) {
|
||||
binary = nvlist_get_binary(nvl_device, "h4", &size);
|
||||
if (binary && size < MAX_AWG_STRING_LEN)
|
||||
{
|
||||
|
|
|
@ -548,25 +548,25 @@ static int parse_device(const struct nlattr *attr, void *data)
|
|||
}
|
||||
break;
|
||||
case WGDEVICE_A_H1:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING)) {
|
||||
device->init_packet_magic_header = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_H1;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_H2:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING)) {
|
||||
device->response_packet_magic_header = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_H2;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_H3:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING)) {
|
||||
device->underload_packet_magic_header = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_H3;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_H4:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING)) {
|
||||
device->transport_packet_magic_header = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_H4;
|
||||
}
|
||||
|
|
|
@ -495,6 +495,32 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
|
||||
out:
|
||||
ret = -errno;
|
||||
if (wgdata.wgd_interface) {
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H1)
|
||||
free(wg_iface->i_init_packet_magic_header);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H2)
|
||||
free(wg_iface->i_response_packet_magic_header);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H3)
|
||||
free(wg_iface->i_underload_packet_magic_header);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H4)
|
||||
free(wg_iface->i_transport_packet_magic_header);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I1)
|
||||
free(wg_iface->i_i1);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I2)
|
||||
free(wg_iface->i_i2);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I3)
|
||||
free(wg_iface->i_i3);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I4)
|
||||
free(wg_iface->i_i4);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I5)
|
||||
free(wg_iface->i_i5);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J1)
|
||||
free(wg_iface->i_j1);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J2)
|
||||
free(wg_iface->i_j2);
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J3)
|
||||
free(wg_iface->i_j3);
|
||||
}
|
||||
free(wgdata.wgd_interface);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -525,28 +525,28 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
|
||||
if (dev->flags & WGDEVICE_HAS_H1) {
|
||||
const size_t init_size = strlen(dev->init_packet_magic_header) + 1;
|
||||
wg_iface->InitPacketMagicHeader = (char*)init_size;
|
||||
wg_iface->InitPacketMagicHeader = (UCHAR*)malloc(init_size);
|
||||
memcpy(wg_iface->InitPacketMagicHeader, dev->init_packet_magic_header, init_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_H1;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_H2) {
|
||||
const size_t response_size = strlen(dev->response_packet_magic_header) + 1;
|
||||
wg_iface->ResponsePacketMagicHeader = (char*)response_size;
|
||||
wg_iface->ResponsePacketMagicHeader = (UCHAR*)malloc(response_size);
|
||||
memcpy(wg_iface->ResponsePacketMagicHeader, dev->response_packet_magic_header, response_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_H2;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_H3) {
|
||||
const size_t underload_size = strlen(dev->underload_packet_magic_header) + 1;
|
||||
wg_iface->UnderloadPacketMagicHeader = (char*)underload_size;
|
||||
wg_iface->UnderloadPacketMagicHeader = (UCHAR*)malloc(underload_size);
|
||||
memcpy(wg_iface->UnderloadPacketMagicHeader, dev->underload_packet_magic_header, underload_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_H3;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_H4) {
|
||||
const size_t transport_size = strlen(dev->transport_packet_magic_header) + 1;
|
||||
wg_iface->TransportPacketMagicHeader = (char*)transport_size;
|
||||
wg_iface->TransportPacketMagicHeader = (UCHAR*)malloc(transport_size);
|
||||
memcpy(wg_iface->TransportPacketMagicHeader, dev->transport_packet_magic_header, transport_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_H4;
|
||||
}
|
||||
|
@ -672,6 +672,20 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
|
||||
out:
|
||||
ret = -errno;
|
||||
if (wg_iface) {
|
||||
free(wg_iface->InitPacketMagicHeader);
|
||||
free(wg_iface->ResponsePacketMagicHeader);
|
||||
free(wg_iface->UnderloadPacketMagicHeader);
|
||||
free(wg_iface->TransportPacketMagicHeader);
|
||||
free(wg_iface->I1);
|
||||
free(wg_iface->I2);
|
||||
free(wg_iface->I3);
|
||||
free(wg_iface->I4);
|
||||
free(wg_iface->I5);
|
||||
free(wg_iface->J1);
|
||||
free(wg_iface->J2);
|
||||
free(wg_iface->J3);
|
||||
}
|
||||
free(wg_iface);
|
||||
CloseHandle(handle);
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue