]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: make errors returned by verify_unix_socket() systematic
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2024 15:23:24 +0000 (17:23 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 25 Apr 2024 20:17:30 +0000 (22:17 +0200)
Previously, if we encountered a non-socket fd we'd return ENOTSOCK the
first time, but the subsequent times we'd return ENOMEDIUM, due to
caching. Let's make sure we return the same errors all the the time.

src/shared/varlink.c

index d96967b8e6a7bcc1f50add28b2e21385ef102cd9..034e72b1db8af34ce7aa4be800778febd9b748d4 100644 (file)
@@ -3170,6 +3170,16 @@ int varlink_take_fd(Varlink *v, size_t i) {
 static int verify_unix_socket(Varlink *v) {
         assert(v);
 
+        /* Returns:
+         *    • 0 if this is an AF_UNIX socket
+         *    • -ENOTSOCK if this is not a socket at all
+         *    • -ENOMEDIUM if this is a socket, but not an AF_UNIX socket
+         *
+         * Reminder:
+         *    • v->af is < 0 if we haven't checked what kind of address family the thing is yet.
+         *    • v->af == AF_UNSPEC if we checked but it's not a socket
+         *    • otherwise: v->af contains the address family we determined */
+
         if (v->af < 0) {
                 struct stat st;
 
@@ -3185,7 +3195,8 @@ static int verify_unix_socket(Varlink *v) {
                         return v->af;
         }
 
-        return v->af == AF_UNIX ? 0 : -ENOMEDIUM;
+        return v->af == AF_UNIX ? 0 :
+                v->af == AF_UNSPEC ? -ENOTSOCK : -ENOMEDIUM;
 }
 
 int varlink_set_allow_fd_passing_input(Varlink *v, bool b) {