mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Always close file dscriptor on error.
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@157 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -396,7 +396,7 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
|
|||||||
const char *key_file, int timeout, int how2verify,
|
const char *key_file, int timeout, int how2verify,
|
||||||
struct crypt_device *cd)
|
struct crypt_device *cd)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
const int verify = how2verify & CRYPT_FLAG_VERIFY;
|
const int verify = how2verify & CRYPT_FLAG_VERIFY;
|
||||||
const int verify_if_possible = how2verify & CRYPT_FLAG_VERIFY_IF_POSSIBLE;
|
const int verify_if_possible = how2verify & CRYPT_FLAG_VERIFY_IF_POSSIBLE;
|
||||||
char *pass = NULL;
|
char *pass = NULL;
|
||||||
@@ -498,8 +498,6 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
|
|||||||
if(r == 0 || (newline_stop && pass[i] == '\n'))
|
if(r == 0 || (newline_stop && pass[i] == '\n'))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(key_file)
|
|
||||||
close(fd);
|
|
||||||
/* Fail if piped input dies reading nothing */
|
/* Fail if piped input dies reading nothing */
|
||||||
if(!i && !regular_file) {
|
if(!i && !regular_file) {
|
||||||
log_dbg("Error reading passphrase.");
|
log_dbg("Error reading passphrase.");
|
||||||
@@ -509,9 +507,13 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
|
|||||||
*key = pass;
|
*key = pass;
|
||||||
*passLen = i;
|
*passLen = i;
|
||||||
}
|
}
|
||||||
|
if(fd != STDIN_FILENO)
|
||||||
|
close(fd);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
out_err:
|
out_err:
|
||||||
|
if(fd >= 0 && fd != STDIN_FILENO)
|
||||||
|
close(fd);
|
||||||
if(pass)
|
if(pass)
|
||||||
safe_free(pass);
|
safe_free(pass);
|
||||||
*key = NULL;
|
*key = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user