]> err.no Git - systemd/commitdiff
ask-password: always send final NUL char
authorLennart Poettering <lennart@poettering.net>
Wed, 13 Apr 2011 19:26:30 +0000 (21:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 Apr 2011 19:26:30 +0000 (21:26 +0200)
src/reply-password.c
src/tty-ask-password-agent.c

index 575a437645283497ee70fb0a6d7d512474bc7d94..bd55e65f3c3450165d0de6650e3cb38f8580d91f 100644 (file)
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 truncate_nl(packet+1);
-                length = strlen(packet+1) + 1;
+                length = 1 + strlen(packet+1) + 1;
         } else if (streq(argv[1], "0")) {
                 packet[0] = '-';
                 length = 1;
index dcf4b332b3beed1c87a1ef51d37e20d99d5c8a92..a414cba3748c27c16cba6ad82a5fbc2f5a4f7bbb 100644 (file)
@@ -369,10 +369,15 @@ static int parse_password(const char *filename, char **wall) {
                                 release_terminal();
                         }
 
-                        asprintf(&packet, "+%s", password);
-                        free(password);
+                        packet_length = 1+strlen(password)+1;
+                        if (!(packet = new(char, packet_length)))
+                                r = -ENOMEM;
+                        else {
+                                packet[0] = '+';
+                                strcpy(packet+1, password);
+                        }
 
-                        packet_length = strlen(packet);
+                        free(password);
                 }
 
                 if (r == -ETIME || r == -ENOENT) {
@@ -382,17 +387,10 @@ static int parse_password(const char *filename, char **wall) {
                 }
 
                 if (r < 0) {
-
                         log_error("Failed to query password: %s", strerror(-r));
                         goto finish;
                 }
 
-                if (!packet) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
-                        goto finish;
-                }
-
                 if ((socket_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
                         log_error("socket(): %m");
                         r = -errno;