From 925b6f0ec83ee09b116e3ec9b457e0bf0a5bad9f Mon Sep 17 00:00:00 2001 From: Seppia Date: Sat, 7 Jul 2018 07:46:52 +0200 Subject: Pad too small check Adds check for pad size relatively to input size and exit with an error when pad is smaller. --- src/onetimebluh.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/onetimebluh.c') diff --git a/src/onetimebluh.c b/src/onetimebluh.c index db65a58..c89b7f3 100644 --- a/src/onetimebluh.c +++ b/src/onetimebluh.c @@ -189,6 +189,14 @@ void xor (Opts* opzioni) { mess_size = strlen (input); } + fseek (keyx, 0L, SEEK_END); + int64_t pad_size = ftell (keyx); + + if (pad_size < mess_size) { + eprintf("ERROR: your pad is too small!\n"); + exit (EXIT_FAILURE); + } + char* bytes; if (opzioni->input) { @@ -211,8 +219,6 @@ void xor (Opts* opzioni) { if (opzioni->tear) { - fseek (keyx, 0L, SEEK_END); - int64_t pad_size = ftell (keyx); ftruncate (fileno (keyx), (pad_size - mess_size)); fseek (keyx, 0L, SEEK_END); int64_t new_pad_size = ftell (keyx); -- cgit v1.2.3