Print a warning when ignoring excess command-line arguments.

This commit is contained in:
LoRd_MuldeR 2021-04-11 20:55:39 +02:00
parent 772c88a387
commit ff48e473a9
Signed by: mulder
GPG Key ID: 2B5913365F57E03F

View File

@ -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); FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%%\n\n"), 100.0);
fflush(stderr);
result = EXIT_SUCCESS; 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); 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); const uint64_t checksum_stored = load_ui64(checksum_buffer);
if (checksum_actual != checksum_stored) 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 <MuldeR2@GMX.de>\n"), OS_TYPE, CPU_ARCH); FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR <MuldeR2@GMX.de>\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); 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 */ /* Parse arguments */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -850,6 +850,11 @@ int MAIN(const int argc, CHR *const argv[])
goto clean_up; 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 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]; 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); 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 */ /* Encrypt or decrypt */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -928,10 +935,8 @@ int MAIN(const int argc, CHR *const argv[])
if (!g_slunkcrypt_abort_flag) if (!g_slunkcrypt_abort_flag)
{ {
FPUTS(T("--------\n\n"), stderr);
fflush(stderr);
const clock_t clk_end = clock(); 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: clean_up:
fflush(stderr);
if (passphrase_buffer) if (passphrase_buffer)
{ {
slunkcrypt_bzero(passphrase_buffer, strlen(passphrase_buffer)); slunkcrypt_bzero(passphrase_buffer, strlen(passphrase_buffer));