From ff48e473a90547bbd6aeb67d154a21a12218af3c Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 11 Apr 2021 20:55:39 +0200 Subject: [PATCH] Print a warning when ignoring excess command-line arguments. --- frontend/src/main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/main.c b/frontend/src/main.c index bf74ec8..2083ba2 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -423,7 +423,6 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co } FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); - fflush(stderr); result = EXIT_SUCCESS; @@ -612,7 +611,6 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co } FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); - fflush(stderr); const uint64_t checksum_stored = load_ui64(checksum_buffer); if (checksum_actual != checksum_stored) @@ -812,6 +810,8 @@ int MAIN(const int argc, CHR *const argv[]) FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR \n"), OS_TYPE, CPU_ARCH); FPRINTF(stderr, T("Using libSlunkCrypt v%u.%u.%u [%") T(PRIstr) T("]\n\n"), SLUNKCRYPT_VERSION_MAJOR, SLUNKCRYPT_VERSION_MINOR, SLUNKCRYPT_VERSION_PATCH, SLUNKCRYPT_BUILD); + fflush(stderr); + /* ----------------------------------------------------- */ /* Parse arguments */ /* ----------------------------------------------------- */ @@ -850,6 +850,11 @@ int MAIN(const int argc, CHR *const argv[]) goto clean_up; } + if (argc > 5) + { + FPUTS(T("Warning: Excess command-line argument(s) will be ignored!\n\n"), stderr); + } + const CHR *const passphrase = PW_FROM_ENV ? GETENV(ENV_PASSWORD) : argv[2U]; const CHR *const input_file = argv[PW_FROM_ENV ? 2U : 3U], *const output_file = argv[PW_FROM_ENV ? 3U : 4U]; @@ -908,6 +913,8 @@ int MAIN(const int argc, CHR *const argv[]) FPUTS(T("Warning: Using a *weak* passphrase; a mix of upper-case letters, lower-case letters, digits and 'special' characters is recommended!\n\n"), stderr); } + fflush(stderr); + /* ----------------------------------------------------- */ /* Encrypt or decrypt */ /* ----------------------------------------------------- */ @@ -928,10 +935,8 @@ int MAIN(const int argc, CHR *const argv[]) if (!g_slunkcrypt_abort_flag) { - FPUTS(T("--------\n\n"), stderr); - fflush(stderr); const clock_t clk_end = clock(); - FPRINTF(stderr, T("Operation completed after %.1f seconds.\n\n"), (clk_end - clk_start) / ((double)CLOCKS_PER_SEC)); + FPRINTF(stderr, T("--------\n\nOperation completed after %.1f seconds.\n\n"), (clk_end - clk_start) / ((double)CLOCKS_PER_SEC)); } /* ----------------------------------------------------- */ @@ -939,7 +944,9 @@ int MAIN(const int argc, CHR *const argv[]) /* ----------------------------------------------------- */ clean_up: - + + fflush(stderr); + if (passphrase_buffer) { slunkcrypt_bzero(passphrase_buffer, strlen(passphrase_buffer));