]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tty-ask-password-agent: assing sendto() result to a ssize_t variable, not an int
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Feb 2018 22:53:59 +0000 (23:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 Feb 2018 22:53:59 +0000 (23:53 +0100)
We should be careful with these types, and if we do convert between
"int" and "ssize_t" we should do so explicitly rather than implicitly.
Otherwise this just looks like a bug.

src/tty-ask-password-agent/tty-ask-password-agent.c

index 33b7e6010fdc39f23d4b1ee7b265661341b812f4..871ac27f0e02fa2e12196e310b53ac47128e55dc 100644 (file)
@@ -254,6 +254,7 @@ static int send_passwords(const char *socket_name, char **passwords) {
         union sockaddr_union sa = { .un.sun_family = AF_UNIX };
         size_t packet_length = 1;
         char **p, *d;
+        ssize_t n;
         int r;
 
         assert(socket_name);
@@ -279,9 +280,13 @@ static int send_passwords(const char *socket_name, char **passwords) {
 
         strncpy(sa.un.sun_path, socket_name, sizeof(sa.un.sun_path));
 
-        r = sendto(socket_fd, packet, packet_length, MSG_NOSIGNAL, &sa.sa, SOCKADDR_UN_LEN(sa.un));
-        if (r < 0)
+        n = sendto(socket_fd, packet, packet_length, MSG_NOSIGNAL, &sa.sa, SOCKADDR_UN_LEN(sa.un));
+        if (n < 0) {
                 r = log_debug_errno(errno, "sendto(): %m");
+                goto finish;
+        }
+
+        r = (int) n;
 
 finish:
         explicit_bzero(packet, packet_length);