Slightly improved cleansing of the command-line on Win32.

This commit is contained in:
LoRd_MuldeR 2020-12-12 17:20:18 +01:00
parent 334d828c5b
commit f250143f8b
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
2 changed files with 27 additions and 7 deletions

View File

@ -21,6 +21,7 @@
#include <inttypes.h>
#include <ctype.h>
#include <signal.h>
#include <assert.h>
/* Const */
#define BUFFER_SIZE 4096U
@ -329,6 +330,7 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co
}
const size_t padding = sizeof(uint64_t) - (file_size % sizeof(uint64_t));
assert(padding && (padding <= sizeof(uint64_t)));
if (slunkcrypt_random_bytes(buffer, padding) < padding)
{
FPUTS(T("\n\nSlunkCrypt error: Failed to generate random data!\n\n"), stderr);
@ -503,6 +505,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co
}
const size_t padding = GET_LOWBITS(buffer[sizeof(uint64_t) - 1U]) + 1U;
assert(padding && (padding <= sizeof(uint64_t)));
if (padding != sizeof(uint64_t))
{
const size_t count = sizeof(uint64_t) - padding;

View File

@ -48,22 +48,39 @@
// Terminal initialization
// ==========================================================================
/* CRT imports */
#if defined(_WIN32) && !defined(_DLL)
#ifdef _WIN32
#ifdef _DLL
#define _acmdln GetCommandLineA()
#define _wcmdln GetCommandLineW()
#else
extern char *const _acmdln;
extern wchar_t *const _wcmdln;
#endif
static void clear_cmdline_args(char *const acmdln, wchar_t *const wcmdln)
{
if (acmdln && acmdln[0U])
{
const size_t len = strlen(acmdln);
slunkcrypt_bzero(acmdln, len * sizeof(char));
if (len > 5U) strcpy(acmdln, "slunk");
}
if (wcmdln && wcmdln[0U])
{
const size_t len = wcslen(wcmdln);
slunkcrypt_bzero(wcmdln, len * sizeof(wchar_t));
if (len > 5U) wcscpy(wcmdln, L"slunk");
}
}
#endif
void init_terminal(void)
{
#ifdef _WIN32
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stderr), _O_U8TEXT);
#ifndef _DLL
if (_acmdln) slunkcrypt_bzero(_acmdln, strlen(_acmdln) * sizeof(char));
if (_wcmdln) slunkcrypt_bzero(_wcmdln, wcslen(_wcmdln) * sizeof(wchar_t));
#endif
clear_cmdline_args(_acmdln, _wcmdln);
#endif
}