Fix error handling during reading passhrase.
authorMilan Broz <gmazyland@gmail.com>
Fri, 11 Dec 2009 11:56:25 +0000 (11:56 +0000)
committerMilan Broz <gmazyland@gmail.com>
Fri, 11 Dec 2009 11:56:25 +0000 (11:56 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@154 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/utils.c

index cf19eb2..02e5ebc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-12-11  Milan Broz  <mbroz@redhat.com>
+       * Fix error handling during reading passhrase.
+
 2009-12-01  Milan Broz  <mbroz@redhat.com>
        * Allow changes of default compiled-in cipher parameters through configure.
        * Switch default key size for LUKS to 256bits.
index 034595c..75c4a69 100644 (file)
@@ -403,6 +403,7 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
        int newline_stop;
        int read_horizon;
        int regular_file = 0;
+       int r;
 
        if(key_file && !strcmp(key_file, "-")) {
                /* Allow binary reading from stdin */
@@ -487,7 +488,14 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
                                        goto out_err;
                                }
                        }
-                       if(read(fd, pass + i, 1) != 1 || (newline_stop && pass[i] == '\n'))
+
+                       r = read(fd, pass + i, 1);
+                       if (r < 0) {
+                               log_err(cd, _("Error reading passphrase.\n"));
+                               goto out_err;
+                       }
+
+                       if(r == 0 || (newline_stop && pass[i] == '\n'))
                                break;
                }
                if(key_file)