swrap: add better logging to convert_un_in()
authorStefan Metzmacher <metze@samba.org>
Fri, 5 Feb 2021 12:13:07 +0000 (13:13 +0100)
committerAndreas Schneider <asn@samba.org>
Fri, 5 Feb 2021 13:11:31 +0000 (14:11 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 14d0dda00d25cd94643630eaf178bcf14c13f42b..5839a5c65c8091e83bad298817dbc167e2f0d193 100644 (file)
@@ -1885,31 +1885,40 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, sock
        if (p) p++; else p = un->sun_path;
 
        if (sscanf(p, SOCKET_FORMAT, &type, &iface, &prt) != 3) {
+               SWRAP_LOG(SWRAP_LOG_ERROR, "sun_path[%s] p[%s]",
+                         un->sun_path, p);
                errno = EINVAL;
                return -1;
        }
 
-       SWRAP_LOG(SWRAP_LOG_TRACE, "type %c iface %u port %u",
-                       type, iface, prt);
-
        if (iface == 0 || iface > MAX_WRAPPED_INTERFACES) {
+               SWRAP_LOG(SWRAP_LOG_ERROR, "type %c iface %u port %u",
+                         type, iface, prt);
                errno = EINVAL;
                return -1;
        }
 
        if (prt > 0xFFFF) {
+               SWRAP_LOG(SWRAP_LOG_ERROR, "type %c iface %u port %u",
+                         type, iface, prt);
                errno = EINVAL;
                return -1;
        }
 
+       SWRAP_LOG(SWRAP_LOG_TRACE, "type %c iface %u port %u",
+                 type, iface, prt);
+
        switch(type) {
        case SOCKET_TYPE_CHAR_TCP:
        case SOCKET_TYPE_CHAR_UDP: {
                struct sockaddr_in *in2 = (struct sockaddr_in *)(void *)in;
 
                if ((*len) < sizeof(*in2)) {
-                   errno = EINVAL;
-                   return -1;
+                       SWRAP_LOG(SWRAP_LOG_ERROR,
+                                 "V4: *len(%zu) < sizeof(*in2)=%zu",
+                                 (size_t)*len, sizeof(*in2));
+                       errno = EINVAL;
+                       return -1;
                }
 
                memset(in2, 0, sizeof(*in2));
@@ -1926,6 +1935,10 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, sock
                struct sockaddr_in6 *in2 = (struct sockaddr_in6 *)(void *)in;
 
                if ((*len) < sizeof(*in2)) {
+                       SWRAP_LOG(SWRAP_LOG_ERROR,
+                                 "V6: *len(%zu) < sizeof(*in2)=%zu",
+                                 (size_t)*len, sizeof(*in2));
+                       SWRAP_LOG(SWRAP_LOG_ERROR, "LINE:%d", __LINE__);
                        errno = EINVAL;
                        return -1;
                }
@@ -1941,6 +1954,8 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, sock
        }
 #endif
        default:
+               SWRAP_LOG(SWRAP_LOG_ERROR, "type %c iface %u port %u",
+                         type, iface, prt);
                errno = EINVAL;
                return -1;
        }