2009-10-03 00:43:04 +02:00
|
|
|
From 6b92a27195e21e9d96ce2f324c3da593a01a7ae0 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Ludwig Nussel <ludwig.nussel@suse.de>
|
|
|
|
Date: Tue, 29 Sep 2009 11:09:31 +0200
|
|
|
|
Subject: [PATCH] Fail if piped input is broken.
|
|
|
|
|
|
|
|
---
|
|
|
|
ChangeLog | 1 +
|
|
|
|
lib/utils.c | 13 ++++++++++---
|
|
|
|
2 files changed, 11 insertions(+), 3 deletions(-)
|
|
|
|
|
2009-09-25 00:02:30 +02:00
|
|
|
Index: cryptsetup-1.0.7/lib/utils.c
|
|
|
|
===================================================================
|
|
|
|
--- cryptsetup-1.0.7.orig/lib/utils.c
|
|
|
|
+++ cryptsetup-1.0.7/lib/utils.c
|
2009-10-03 00:43:04 +02:00
|
|
|
@@ -361,6 +361,7 @@ int get_key(char *prompt, char **key, un
|
|
|
|
char *pass = NULL;
|
|
|
|
int newline_stop;
|
|
|
|
int read_horizon;
|
|
|
|
+ int regular_file = 0;
|
|
|
|
|
|
|
|
if(key_file && !strcmp(key_file, "-")) {
|
|
|
|
/* Allow binary reading from stdin */
|
|
|
|
@@ -435,6 +436,8 @@ int get_key(char *prompt, char **key, un
|
|
|
|
// goto out_err;
|
|
|
|
fprintf(stderr,"Warning: exhausting read requested, but key file is not a regular file, function might never return.\n");
|
|
|
|
}
|
|
|
|
+ else
|
|
|
|
+ regular_file = 1;
|
|
|
|
}
|
|
|
|
buflen = 0;
|
|
|
|
for(i = 0; read_horizon == 0 || i < read_horizon; i++) {
|
|
|
|
@@ -452,6 +455,10 @@ int get_key(char *prompt, char **key, un
|
2009-09-25 00:02:30 +02:00
|
|
|
}
|
|
|
|
if(key_file)
|
|
|
|
close(fd);
|
2009-10-03 00:43:04 +02:00
|
|
|
+ /* Fail if piped input dies reading nothing */
|
|
|
|
+ if(!i && !regular_file) {
|
2009-09-25 00:02:30 +02:00
|
|
|
+ goto out_err;
|
2009-10-03 00:43:04 +02:00
|
|
|
+ }
|
2009-09-25 00:02:30 +02:00
|
|
|
pass[i] = 0;
|
|
|
|
*key = pass;
|
|
|
|
*passLen = i;
|