File 7754-kernel-erts-Fixed-offset-add-drop-_membership-bug-of.patch of Package erlang

From 90938ce7188e05e356d92f03ec7df60396b429d1 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Fri, 18 Nov 2022 18:56:35 +0100
Subject: [PATCH 4/5] [kernel|erts] Fixed offset [add|drop]_membership bug
 offset bug

Offset bug while processing add_membership and drop_membership
options causing options after in the options list to be invalid
and therefor not processed properly.

OTP-18323
---
 erts/emulator/drivers/common/inet_drv.c | 117 +++++++++++++++---------
 1 file changed, 74 insertions(+), 43 deletions(-)

diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c
index 8baf496e44..6cfa775297 100644
--- a/erts/emulator/drivers/common/inet_drv.c
+++ b/erts/emulator/drivers/common/inet_drv.c
@@ -140,9 +140,13 @@
 #define M2S(__M__)   (((__M__) == INET_MODE_LIST) ? "list" :      \
                       (((__M__) == INET_MODE_BINARY) ? "binary" : \
                        "undefined"))
-#define D2S(__D__)   (((__D__) == INET_DELIVER_PORT) ? "port" :  \
-                      (((__D__) == INET_DELIVER_TERM) ? "term" : \
+#define D2S(__D__)   (((__D__) == INET_DELIVER_PORT) ? "port" :         \
+                      (((__D__) == INET_DELIVER_TERM) ? "term" :        \
                        "undefined"))
+#define DOM2S(__D__)   (((__D__) == INET_AF_INET) ? "inet" :         \
+                        (((__D__) == INET_AF_INET6) ? "inet6" :      \
+                         (((__D__) == INET_AF_LOCAL) ? "local" :     \
+                          "undefined")))
 
 #if defined(__WIN32__) && defined(ARCH_64)
 #define SOCKET_FSTR "%lld"
@@ -7188,8 +7192,9 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
 	case UDP_OPT_ADD_MEMBERSHIP:
             DDBG(desc,
                  ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
-                  "inet_set_opts(add-membership) -> %d\r\n",
-                  __LINE__, desc->s, driver_caller(desc->port), ival) );
+                  "inet_set_opts(add-membership) -> domain: %d (%s)\r\n",
+                  __LINE__, desc->s, driver_caller(desc->port),
+                  ival, DOM2S(ival)) );
             if (ival == INET_AF_INET) {
                 proto = IPPROTO_IP;
                 type  = IP_ADD_MEMBERSHIP;
@@ -7212,8 +7217,9 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
 	case UDP_OPT_DROP_MEMBERSHIP:
             DDBG(desc,
                  ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
-                  "inet_set_opts(drop-membership) -> %d\r\n",
-                  __LINE__, desc->s, driver_caller(desc->port), ival) );
+                  "inet_set_opts(drop-membership) -> %d (%s)\r\n",
+                  __LINE__, desc->s, driver_caller(desc->port),
+                  ival, DOM2S(ival)) );
             if (ival == INET_AF_INET) {
                 proto = IPPROTO_IP;
                 type  = IP_DROP_MEMBERSHIP;
@@ -7240,13 +7246,16 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
                 ptr += 4;
                 len -= 4;
 
-                DEBUGF(("inet_set_opts(L_init_mreq) -> "
-                        "\r\n   proto:  %d"
-                        "\r\n   type:   %d"
-                        "\r\n   domain: %d"
-                        "\r\n   if:     %d"
-                        "\r\n",
-                        proto, type, domain, ival));
+                DDBG(desc,
+                     ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                      "inet_set_opts(L_init_mreq) -> "
+                      "\r\n   proto:  %d"
+                      "\r\n   type:   %d"
+                      "\r\n   domain: %d (%s)"
+                      "\r\n   if:     %d"
+                      "\r\n",
+                      __LINE__, desc->s, driver_caller(desc->port),
+                      proto, type, domain, DOM2S(domain), ival));
 
                 if ((domain == INET_AF_INET) && (desc->sfamily == AF_INET)) {
 
@@ -7259,7 +7268,10 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
                 
 #if defined(HAVE_STRUCT_IP_MREQN)
 
-                    DEBUGF(("inet_set_opts(L_init_mreq,inet) -> mreqn\r\n"));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq,inet) -> mreqn\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port)));
 
                     mreq4.imr_ifindex          = sock_htonl(ival);
                     ival = get_int32(ptr);
@@ -7267,40 +7279,53 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
                     len -= 4;
                     mreq4.imr_multiaddr.s_addr = sock_htonl(ival);
                     ival = get_int32(ptr);
+                    ptr += 4;
+                    len -= 4;
                     mreq4.imr_address.s_addr   = sock_htonl(ival);
 
-                    DEBUGF(("inet_set_opts(L_init_mreq,inet) -> "
-                            "try setopt: "
-                            "\r\n   maddr: %x"
-                            "\r\n   addr:  %x"
-                            "\r\n   if:    %d"
-                            "\r\n   sz:    %d"
-                            "\r\n",
-                            mreq4.imr_multiaddr.s_addr,
-                            mreq4.imr_address.s_addr,
-                            mreq4.imr_ifindex,
-                            mreqSz));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq,inet) -> "
+                          "try setopt: "
+                          "\r\n   maddr: %x"
+                          "\r\n   addr:  %x"
+                          "\r\n   if:    %d"
+                          "\r\n   sz:    %d"
+                          "\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port),
+                          mreq4.imr_multiaddr.s_addr,
+                          mreq4.imr_address.s_addr,
+                          mreq4.imr_ifindex,
+                          mreqSz));
 
 #else
 
-                    DEBUGF(("inet_set_opts(L_init_mreq,inet) -> mreq\r\n"));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq,inet) -> mreq\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port)));
 
                     ival = get_int32(ptr);
                     ptr += 4;
                     len -= 4;
                     mreq4.imr_multiaddr.s_addr = sock_htonl(ival);
                     ival = get_int32(ptr);
+                    ptr += 4;
+                    len -= 4;
                     mreq4.imr_interface.s_addr = sock_htonl(ival);
 
-                    DEBUGF(("inet_set_opts(L_init_mreq,inet) -> "
-                            "try setopt: "
-                            "\r\n   maddr: %x"
-                            "\r\n   if:    %x"
-                            "\r\n   sz:    %d"
-                            "\r\n",
-                            mreq4.imr_multiaddr.s_addr,
-                            mreq4.imr_interface.s_addr,
-                            mreqSz));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq,inet) -> "
+                          "try setopt: "
+                          "\r\n   maddr: %x"
+                          "\r\n   if:    %x"
+                          "\r\n   sz:    %d"
+                          "\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port),
+                          mreq4.imr_multiaddr.s_addr,
+                          mreq4.imr_interface.s_addr,
+                          mreqSz));
 
 #endif
 
@@ -7314,7 +7339,10 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
 
                     mreqSz = sizeof(mreq6);
 
-                    DEBUGF(("inet_set_opts(L_init_mreq,inet6) -> mreq\r\n"));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq,inet6) -> mreq\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port)));
 
                     /* 0) Read out the ifindex
                      * 1) Read out the multiaddr
@@ -7331,13 +7359,16 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len)
                 }
 #endif
                 else {
-                    DEBUGF(("inet_set_opts(L_init_mreq) -> "
-                             "invalid domain: "
-                             "\r\n   domain:  %d (%d, %d)"
-                             "\r\n   sfmaily: %d (%d, %d)"
-                             "\r\n",
-                             domain, INET_AF_INET, INET_AF_INET6,
-                             desc->sfamily, AF_INET, AF_INET6));
+                    DDBG(desc,
+                         ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
+                          "inet_set_opts(L_init_mreq) -> "
+                          "invalid domain: "
+                          "\r\n   domain:  %d (%d, %d)"
+                          "\r\n   sfmaily: %d (%d, %d)"
+                          "\r\n",
+                          __LINE__, desc->s, driver_caller(desc->port),
+                          domain, INET_AF_INET, INET_AF_INET6,
+                          desc->sfamily, AF_INET, AF_INET6));
                     return -1;
                 }
             }
-- 
2.35.3

openSUSE Build Service is sponsored by