Skip to content
Snippets Groups Projects
Commit 248631ae authored by Alaric Senat's avatar Alaric Senat Committed by Hugo Beauzée-Luyssen
Browse files

contrib: upnp: fix bind failures for non-IPv6 netintf

This patch fixes issues when a net intf provides only one version of the
IP protocol when libupnp is built with `--enable-ipv6`.

This has been proposed upstream: https://github.com/pupnp/pupnp/pull/398

Refs #27001
parent c3ab95b2
No related branches found
No related tags found
Loading
Pipeline #234248 passed with stage
in 14 minutes and 57 seconds
From 06b60ad252d962b21071f157ec0c377c66b2492b Mon Sep 17 00:00:00 2001
From: Alaric Senat <dev.asenat@posteo.net>
Date: Thu, 9 Jun 2022 15:19:23 +0200
Subject: [PATCH] miniserver: Don't initialize sockets for invalid IPs
`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...
Refs #195
---
upnp/src/genlib/miniserver/miniserver.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c
index 1a313a36..09fe3fbf 100644
--- a/upnp/src/genlib/miniserver/miniserver.c
+++ b/upnp/src/genlib/miniserver/miniserver.c
@@ -756,7 +756,10 @@ static int init_socket_suff(
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);
--
2.35.3
......@@ -54,6 +54,7 @@ ifdef HAVE_ANDROID
endif
$(APPLY) $(SRC)/upnp/miniserver.patch
$(APPLY) $(SRC)/upnp/upnp-no-debugfile.patch
$(APPLY) $(SRC)/upnp/miniserver-pton-error.patch
$(UPDATE_AUTOCONFIG)
$(MOVE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment