Skip to content

Commit

Permalink
Clear c->ip and c->ipv6 buffers before reset
Browse files Browse the repository at this point in the history
Trac: #1064
Signed-off-by: Selva Nair <selva.nair@gmail.com>
  • Loading branch information
selvanair committed Jun 16, 2018
1 parent 0f3ed6c commit 3ba0615
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions openvpn.c
Expand Up @@ -204,18 +204,25 @@ static void
parse_assigned_ip(connection_t *c, const char *msg)
{
char *sep;
CLEAR(c->ip);
CLEAR(c->ipv6);

/* extract local ipv4 address if available*/
c->ip[0] = L'\0';
sep = strchr(msg, ',');
if (sep == NULL)
return;

/* Convert the IP address to Unicode */
MultiByteToWideChar(CP_UTF8, 0, msg, sep-msg, c->ip, _countof(c->ip));
if (sep - msg > 0
&& MultiByteToWideChar(CP_UTF8, 0, msg, sep-msg, c->ip, _countof(c->ip)-1) == 0)
{
WriteStatusLog(c, L"GUI> ", L"Failed to extract the assigned ipv4 address (error = %d)",
GetLastError());
c->ip[0] = L'\0';
}

/* extract local ipv6 address if available */
c->ipv6[0] = L'\0';

/* skip 4 commas */
for (int i = 0; i < 4 && sep; i++)
{
Expand All @@ -226,7 +233,12 @@ parse_assigned_ip(connection_t *c, const char *msg)

sep++; /* start of ipv6 address */
/* Convert the IP address to Unicode */
MultiByteToWideChar(CP_UTF8, 0, sep, -1, c->ipv6, _countof(c->ipv6));
if (MultiByteToWideChar(CP_UTF8, 0, sep, -1, c->ipv6, _countof(c->ipv6)-1) == 0)
{
WriteStatusLog(c, L"GUI> ", L"Failed to extract the assigned ipv6 address (error = %d)",
GetLastError());
c->ipv6[0] = L'\0';
}
}

/*
Expand Down

0 comments on commit 3ba0615

Please sign in to comment.