Skip to content

Commit

Permalink
Prevented a potential memory leak in case of input_file or output_fil…
Browse files Browse the repository at this point in the history
…e fopen() failures.
  • Loading branch information
GlitchedPolygons committed Oct 9, 2021
1 parent 007be00 commit e77bf83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pwcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ int pwcrypt_encrypt_file(const char* input_file_path, size_t input_file_path_len

if (input_file == NULL || output_file == NULL)
{
return PWCRYPT_ERROR_FILE_FAILURE;
pwcrypt_fprintf(stderr, "pwcrypt: \"pwcrypt_encrypt_file\" function failed to open input and/or output file.");
r = PWCRYPT_ERROR_FILE_FAILURE;
goto exit;
}

r = ccrush_compress_file(input_file_path, temp_file_path, 4096, (int)compress);
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ static void encrypt_and_decrypt_file_wrong_args_fail()

TEST_CHECK(r == PWCRYPT_ERROR_INVALID_ARGS);

r = pwcrypt_encrypt_file(tmp_in_file, strlen(tmp_in_file), 6, (uint8_t*)"Weak Pw", 7, 0, 0, 0, 0, tmp_out_file, strlen(tmp_out_file));

TEST_CHECK(r != 0);

r = pwcrypt_encrypt_file(tmp_in_file, strlen(tmp_in_file) - 3, 6, (uint8_t*)"Test Password 456 ^^ ~ ? ¨", 27, 0, 0, 0, 0, tmp_out_file, strlen(tmp_out_file));

TEST_CHECK(r == PWCRYPT_ERROR_INVALID_ARGS);
Expand Down

0 comments on commit e77bf83

Please sign in to comment.