Skip to content

Commit

Permalink
miniserver: Don't initialize sockets for invalid IPs
Browse files Browse the repository at this point in the history
`init_socket_stuff` was ignoring `inet_pton`'s return value causing
invalid IPs being seen as valid which caused bad calls to `bind` and
`listen` further in the code path.

Invalid `bind`s were frequents for interfaces providing only one IP
protocol version (IPv4 or v6). In those cases, `gIF_IPV4` or `gIF_IPV4`
were left to their default values (an empty string) causing `inet_pton`
to fail silently without aborting the socket opening and binding...

Fixes pupnp#195
  • Loading branch information
AlaricSenat committed Jun 9, 2022
1 parent 2205f05 commit 447de4e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion upnp/src/genlib/miniserver/miniserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,10 @@ static int init_socket_suff(UpnpLib *p,
goto error;
break;
}
inet_pton(domain, text_addr, addr);

if (inet_pton(domain, text_addr, addr) <= 0)
goto error;

s->fd = socket(domain, SOCK_STREAM, 0);
if (s->fd == INVALID_SOCKET) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
Expand Down

0 comments on commit 447de4e

Please sign in to comment.