]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: net_listen|connect_unix() - Use consistent error handling for too long paths
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 28 Aug 2020 15:36:47 +0000 (18:36 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 11 Sep 2020 13:34:56 +0000 (13:34 +0000)
The errno should be the same for both functions. Prefer ENAMETOOLONG if it
exists on the OS, otherwise fallback to EOVERFLOW.

src/lib/net.c
src/lib/test-net.c

index d94f9a5986c91abb92d899359417985bce02746f..b4a940b3e5ca6cdcac3fa9ea00e0683e3cabc11d 100644 (file)
@@ -279,7 +279,7 @@ int net_connect_unix(const char *path)
 #ifdef ENAMETOOLONG
                errno = ENAMETOOLONG;
 #else
-               errno = EINVAL;
+               errno = EOVERFLOW;
 #endif
                return -1;
        }
@@ -513,7 +513,11 @@ int net_listen_unix(const char *path, int backlog)
        sa.un.sun_family = AF_UNIX;
        if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
                /* too long path */
+#ifdef ENAMETOOLONG
+               errno = ENAMETOOLONG;
+#else
                errno = EOVERFLOW;
+#endif
                return -1;
        }
 
index 5018a3257a7a05e7cf098d6002f81a6c41bde486..fb19d5bf0d8f1970d65cdc2ff4f486a3cd6e88bc 100644 (file)
@@ -135,9 +135,33 @@ static void test_net_str2hostport(void)
        test_end();
 }
 
+static void test_net_unix_long_paths(void)
+{
+#ifdef ENAMETOOLONG
+       int long_errno = ENAMETOOLONG;
+#else
+       int long_errno = EOVERFLOW;
+#endif
+
+       test_begin("net_*_unix() - long paths");
+
+       char path[PATH_MAX];
+       memset(path, 'x', sizeof(path)-1);
+       path[sizeof(path)-1] = '\0';
+
+       test_assert(net_listen_unix(path, 1) == -1);
+       test_assert(errno == long_errno);
+
+       test_assert(net_connect_unix(path) == -1);
+       test_assert(errno == long_errno);
+
+       test_end();
+}
+
 void test_net(void)
 {
        test_net_is_in_network();
        test_net_ip2addr();
        test_net_str2hostport();
+       test_net_unix_long_paths();
 }