Fix inverted conditional in sock_same_addr() - quark - quark web server
git clone git://git.suckless.org/quark
Log
Files
Refs
LICENSE
---
commit eead7a5fd2cbe5aa54d278c8171bd9476f91b2e4
parent 68b4f733b2755762e43df90f73db5a6ec8d14104
Author: Thomas Oltmann 
Date:   Tue, 19 Apr 2022 12:04:57 +0200

Fix inverted conditional in sock_same_addr()

sock_same_addr() is supposed to return 0 if sa1 and sa2 are different addresses.
Since memcmp() returns 0 if its arguments are equal, we need to flip the return
value by comparing it to 0.

Diffstat:
  M sock.c                              |       2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/sock.c b/sock.c
@@ -198,7 +198,7 @@ sock_same_addr(const struct sockaddr_storage *sa1, const struct sockaddr_storage
         case AF_INET6:
                 return memcmp(((struct sockaddr_in6 *)sa1)->sin6_addr.s6_addr,
                               ((struct sockaddr_in6 *)sa2)->sin6_addr.s6_addr,
-                              sizeof(((struct sockaddr_in6 *)sa1)->sin6_addr.s6_addr));
+                              sizeof(((struct sockaddr_in6 *)sa1)->sin6_addr.s6_addr)) == 0;
         case AF_INET:
                 return ntohl(((struct sockaddr_in *)sa1)->sin_addr.s_addr) ==
                        ntohl(((struct sockaddr_in *)sa2)->sin_addr.s_addr);