Skip to content

Commit

Permalink
block-dns using iservice: fix a potential double free
Browse files Browse the repository at this point in the history
- An item added to undo-list was not removed on error, causing
  attempt to free again in Undo().
  Also fix a memory leak possibility in the same context.

Github: fixes OpenVPN#232

Signed-off-by: Selva Nair <selva.nair@gmail.com>
  • Loading branch information
selvanair authored and lstipakov committed Feb 1, 2023
1 parent 680ba43 commit 37c8049
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/openvpnserv/interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ static DWORD
HandleBlockDNSMessage(const block_dns_message_t *msg, undo_lists_t *lists)
{
DWORD err = 0;
block_dns_data_t *interface_data;
block_dns_data_t *interface_data = NULL;
HANDLE engine = NULL;
LPCWSTR exe_path;

Expand All @@ -794,6 +794,7 @@ HandleBlockDNSMessage(const block_dns_message_t *msg, undo_lists_t *lists)
interface_data = malloc(sizeof(block_dns_data_t));
if (!interface_data)
{
delete_block_dns_filters(engine);
return ERROR_OUTOFMEMORY;
}
interface_data->engine = engine;
Expand All @@ -818,8 +819,17 @@ HandleBlockDNSMessage(const block_dns_message_t *msg, undo_lists_t *lists)
BLOCK_DNS_IFACE_METRIC);
if (!err)
{
set_interface_metric(msg->iface.index, AF_INET6,
BLOCK_DNS_IFACE_METRIC);
err = set_interface_metric(msg->iface.index, AF_INET6,
BLOCK_DNS_IFACE_METRIC);
}
if (err)
{
/* try to restore the interface metric values in case changed */
set_interface_metric(msg->iface.index, AF_INET,
interface_data->metric_v4);
set_interface_metric(msg->iface.index, AF_INET,
interface_data->metric_v4);
RemoveListItem(&(*lists)[block_dns], CmpAny, NULL);
}
}
}
Expand Down Expand Up @@ -853,6 +863,7 @@ HandleBlockDNSMessage(const block_dns_message_t *msg, undo_lists_t *lists)
if (err && engine)
{
delete_block_dns_filters(engine);
free(interface_data);
}

return err;
Expand Down

0 comments on commit 37c8049

Please sign in to comment.