From: Milan Broz Date: Mon, 28 Sep 2009 18:29:58 +0000 (+0000) Subject: Fail if piped input is broken. X-Git-Tag: upstream/1.6~712 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fddd7125caeb9c7238438b0b10d11cf48fa0260b;p=platform%2Fupstream%2Fcryptsetup.git Fail if piped input is broken. (Thanks to Ludwig Nussel) git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@115 36d66b0a-2a48-0410-832c-cd162a569da5 --- diff --git a/ChangeLog b/ChangeLog index aacf9b4..ab95248 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2009-09-28 Milan Broz * Add luksHeaderBackup and luksHeaderRestore commands. + * Fail passphrase read if piped input no longer exists. 2009-09-15 Milan Broz * Initialize crypto library before LUKS header load. diff --git a/lib/utils.c b/lib/utils.c index 05d33cd..b27c11f 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -402,6 +402,7 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size, char *pass = NULL; int newline_stop; int read_horizon; + int regular_file = 0; if(key_file && !strcmp(key_file, "-")) { /* Allow binary reading from stdin */ @@ -469,11 +470,12 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size, log_err(cd, "Failed to stat key file %s.\n", key_file); goto out_err; } - if(!S_ISREG(st.st_mode)) { + if(!S_ISREG(st.st_mode)) log_err(cd, "Warning: exhausting read requested, but key file %s" " is not a regular file, function might never return.\n", key_file); - } + else + regular_file = 1; } buflen = 0; for(i = 0; read_horizon == 0 || i < read_horizon; i++) { @@ -490,6 +492,11 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size, } if(key_file) close(fd); + /* Fail if piped input dies reading nothing */ + if(!i && !regular_file) { + log_err(cd, "Error reading passphrase.\n"); + goto out_err; + } pass[i] = 0; *key = pass; *passLen = i;