[client] fix memory leak when unable to open --get-key file
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
|
||||
/* prototypes
|
||||
*/
|
||||
static char * get_user_pw(fko_cli_options_t *options, const int crypt_op);
|
||||
static char * get_user_pw(fko_ctx_t ctx,
|
||||
fko_cli_options_t *options, const int crypt_op);
|
||||
static void display_ctx(fko_ctx_t ctx);
|
||||
static void errmsg(const char *msg, const int err);
|
||||
static void show_last_command(void);
|
||||
@@ -284,7 +285,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Finalize the context data (encrypt and encode the SPA data)
|
||||
*/
|
||||
res = fko_spa_data_final(ctx, get_user_pw(&options, CRYPT_OP_ENCRYPT));
|
||||
res = fko_spa_data_final(ctx, get_user_pw(ctx, &options, CRYPT_OP_ENCRYPT));
|
||||
if(res != FKO_SUCCESS)
|
||||
{
|
||||
errmsg("fko_spa_data_final", res);
|
||||
@@ -374,7 +375,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
res = fko_decrypt_spa_data(
|
||||
ctx2, get_user_pw(&options, CRYPT_OP_DECRYPT)
|
||||
ctx2, get_user_pw(ctx2, &options, CRYPT_OP_DECRYPT)
|
||||
);
|
||||
|
||||
if(res != FKO_SUCCESS)
|
||||
@@ -719,7 +720,7 @@ set_message_type(fko_ctx_t ctx, fko_cli_options_t *options)
|
||||
/* Prompt for and receive a user password.
|
||||
*/
|
||||
static char*
|
||||
get_user_pw(fko_cli_options_t *options, const int crypt_op)
|
||||
get_user_pw(fko_ctx_t ctx, fko_cli_options_t *options, const int crypt_op)
|
||||
{
|
||||
char *pw_ptr = NULL;
|
||||
static char *no_pw = "";
|
||||
@@ -736,7 +737,7 @@ get_user_pw(fko_cli_options_t *options, const int crypt_op)
|
||||
*/
|
||||
if (options->get_key_file[0] != 0x0)
|
||||
{
|
||||
pw_ptr = getpasswd_file(options->get_key_file, options->spa_server_str);
|
||||
pw_ptr = getpasswd_file(ctx, options);
|
||||
}
|
||||
else if (options->use_gpg)
|
||||
{
|
||||
@@ -762,6 +763,7 @@ get_user_pw(fko_cli_options_t *options, const int crypt_op)
|
||||
if (pw_ptr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Received no password data, exiting.\n");
|
||||
fko_destroy(ctx);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ getpasswd(const char *prompt)
|
||||
/* Function for accepting password input from from a file
|
||||
*/
|
||||
char*
|
||||
getpasswd_file(const char *pw_file, const char *server_str)
|
||||
getpasswd_file(fko_ctx_t ctx, const fko_cli_options_t *options)
|
||||
{
|
||||
FILE *pwfile_ptr;
|
||||
unsigned int numLines = 0, i = 0, found_dst;
|
||||
@@ -151,10 +151,11 @@ getpasswd_file(const char *pw_file, const char *server_str)
|
||||
char tmp_char_buf[MAX_LINE_LEN] = {0};
|
||||
char *lptr;
|
||||
|
||||
if ((pwfile_ptr = fopen(pw_file, "r")) == NULL)
|
||||
if ((pwfile_ptr = fopen(options->get_key_file, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not open config file: %s\n", pw_file);
|
||||
exit(1);
|
||||
fprintf(stderr, "Could not open config file: %s\n", options->get_key_file);
|
||||
fko_destroy(ctx);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((fgets(conf_line_buf, MAX_LINE_LEN, pwfile_ptr)) != NULL)
|
||||
@@ -178,8 +179,8 @@ getpasswd_file(const char *pw_file, const char *server_str)
|
||||
* reference the matching one for the SPA server we are contacting
|
||||
*/
|
||||
found_dst = 1;
|
||||
for (i=0; i < strlen(server_str); i++)
|
||||
if (*lptr++ != server_str[i])
|
||||
for (i=0; i < strlen(options->spa_server_str); i++)
|
||||
if (*lptr++ != options->spa_server_str[i])
|
||||
found_dst = 0;
|
||||
|
||||
if (! found_dst)
|
||||
@@ -208,8 +209,9 @@ getpasswd_file(const char *pw_file, const char *server_str)
|
||||
|
||||
if (pwbuf[0] == '\0') {
|
||||
fprintf(stderr, "Could not get password for IP: %s from: %s\n",
|
||||
server_str, pw_file);
|
||||
exit(1);
|
||||
options->spa_server_str, options->get_key_file);
|
||||
fko_destroy(ctx);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return pwbuf;
|
||||
|
||||
@@ -34,6 +34,6 @@
|
||||
/* Prototypes
|
||||
*/
|
||||
char* getpasswd(const char *prompt);
|
||||
char* getpasswd_file(const char *pw_file, const char *server_str);
|
||||
char* getpasswd_file(fko_ctx_t ctx, const fko_cli_options_t *options);
|
||||
|
||||
#endif /* GETPASSWD_H */
|
||||
|
||||
Reference in New Issue
Block a user