conserver: free correct addrinfo to prevent crash.
authorDarren Tucker <redacted>
Thu, 15 Feb 2024 08:33:05 +0000 (19:33 +1100)
committerRosen Penev <redacted>
Sat, 24 Feb 2024 20:14:18 +0000 (12:14 -0800)
When looping through addrinfo lists in AddrsMatch, keep a copy of the
original addrinfo pointers to free instead of ending up at the terminating
NULLs and trying to free those.

OpenWRT uses musl in which freeaddrinfo(NULL) is not safe (which is
fine, it's not required by the spec) so this fixes a segfault.

Signed-off-by: Darren Tucker <redacted>
net/conserver/Makefile
net/conserver/patches/002-addrsmatch-freeaddrinfo.patch [new file with mode: 0644]

index ab3f39aacf023dbcb93ed3d64d8eb35d856bd94c..da61bb3495108bbbb9817034b15cfb25a5e5b172 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=conserver
 PKG_VERSION:=8.2.6
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://codeload.github.com/conserver/conserver/tar.gz/v$(PKG_VERSION)?
diff --git a/net/conserver/patches/002-addrsmatch-freeaddrinfo.patch b/net/conserver/patches/002-addrsmatch-freeaddrinfo.patch
new file mode 100644 (file)
index 0000000..1d48c68
--- /dev/null
@@ -0,0 +1,36 @@
+--- a/conserver/consent.c
++++ b/conserver/consent.c
+@@ -1269,7 +1269,7 @@ AddrsMatch(char *addr1, char *addr2)
+ {
+ #if USE_IPV6
+     int error, ret = 0;
+-    struct addrinfo *ai1, *ai2, hints;
++    struct addrinfo *ai1, *ai2, *rp1, *rp2, hints;
+ #else
+     /* so, since we might use inet_addr, we're going to use
+      * (in_addr_t)(-1) as a sign of an invalid ip address.
+@@ -1307,17 +1307,19 @@ AddrsMatch(char *addr1, char *addr2)
+       goto done;
+     }
+-    for (; ai1 != NULL; ai1 = ai1->ai_next) {
+-      for (; ai2 != NULL; ai2 = ai2->ai_next) {
+-          if (ai1->ai_addr->sa_family != ai2->ai_addr->sa_family)
++    rp1 = ai1;
++    rp2 = ai2;
++    for (; rp1 != NULL; rp1 = rp1->ai_next) {
++      for (; rp2 != NULL; rp2 = rp2->ai_next) {
++          if (rp1->ai_addr->sa_family != rp2->ai_addr->sa_family)
+               continue;
+           if (
+ # if HAVE_MEMCMP
+-                 memcmp(&ai1->ai_addr, &ai2->ai_addr,
++                 memcmp(&rp1->ai_addr, &rp2->ai_addr,
+                         sizeof(struct sockaddr_storage))
+ # else
+-                 bcmp(&ai1->ai_addr, &ai2->ai_addr,
++                 bcmp(&rp1->ai_addr, &rp2->ai_addr,
+                       sizeof(struct sockaddr_storage))
+ # endif
+                  == 0) {
git clone https://git.99rst.org/PROJECT