Skip to content

Commit 5ef7b98

Browse files
authored
fix crash for too big terminal console
fix a crash caused by fetching console window’s size. the size were stored in a char which were too small to contain size information of fullscreen console on big screens. Replaced char with int.
1 parent 6dcfeaf commit 5ef7b98

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

main.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void usage(int status)
159159
"NAME\n\t%s -- crypt or decrypt any data\n\nSYNOPSIS\n\t%s [options] FILE|DIRECTORY [KEYFILE]\n\nDESCRIPTION\n\t(FR) Permet de chiffrer et de déchiffrer toutes les données entrées en paramètre. Le mot de passe demandé au début est hashé puis sert de graine pour le PRNG(générateur de nombre aléatoire). Le PRNG permet de fournir une clé unique égale à la longueur du fichier à coder. La clé unique subit un xor avec le mot de passe (le mot de passe est répété autant de fois que nécéssaire). Le fichier subit un xor avec cette nouvelle clé, puis un brouilleur est utilisé. Il mélange la table des caractères (ascii) en utilisant le PRNG et en utilisant le keyfile s'il est fourni. 256 tables de brouillages sont utilisées au total dans un ordre non prédictible donné par la clé unique combiné avec le keyfile s'il est fournit.\n\t(EN) Can crypt and decrypt any data given in argument. The password asked is hashed to be used as a seed for the PRNG(pseudo random number generator). The PRNG gives a unique key which has the same length as the source file. The key is xored with the password (the password is repeated as long as necessary). The file is then xored with this new key, then a scrambler is used. It scrambles the ascii table using the PRNG and the keyfile if it is given. 256 scramble's tables are used in an unpredictible order given by the unique key combined with the keyfile if present.\n\nOPTIONS\n\toptions are as follows:\n\n\t-h | --help\tfurther help.\n\n\t-k | --keyfile\tgenerate keyfile.\n\n\t-s (simple)\tput the scrambler on off.\n\n\t-i (inverted)\tinvert the coding/decoding process, for coding it xors then scrambles and for decoding it scrambles then xors.\n\n\t-n (normalised)\tnormalise the size of the keyfile, if the keyfile is too long (over 1 cycle in the Yates and Fisher algorithm) it will be croped to complete 1 cycle\n\n\t-d (destroy)\twrite on top of the source file (securely erase source data), except when the source is a folder where it's just deleted by the system at the end)\n\n\t-f (force)\tnever ask something to the user after entering password (overwrite the output file if it already exists and treat the second argument as a file if it looks like a set of options)\n\n\t-r (randomize)\trandomize the name of the output file but keeping the extension intact\n\n\t-R (randomize)\trandomize the name of the output file included the extension\n\n\tFILE|DIRECTORY\tthe path to the file or directory to crypt/decrypt\n\n\tKEYFILE \tthe path to a file which will be used to scramble the substitution's tables and choose in which order they will be used instead of the PRNG only (starting at 16 ko for the keyfile is great, however not interesting to be too heavy) \n\nEXIT STATUS\n\tthe %s program exits 0 on success, and anything else if an error occurs.\n\nEXAMPLES\n\tthe command :\t%s file1\n\n\tlets you choose between crypting or decrypting then it will prompt for a password that crypt/decrypt file1 as xfile1 in the same folder, file1 is not modified.\n\n\tthe command :\t%s file2 keyfile1\n\n\tlets you choose between crypting or decrypting, will prompt for the password that crypt/decrypt file2, uses keyfile1 to generate the scrambler then crypt/decrypt file2 as xfile2 in the same folder, file2 is not modified.\n\n\tthe command :\t%s -s file3\n\n\tlets you choose between crypting or decrypting, will prompt for a password that crypt/decrypt the file without using the scrambler(option 's'), resulting in using the unique key only.\n\n\tthe command :\t%s -i file4 keyfile2\n\n\tlets you choose between crypting or decrypting, uses keyfile2 to generate the scramble table and will prompt for a password that crypt/decrypt the file but will inverts the process(option 'i'): first it xors then it scrambles for the coding process or first it unscrambles then it xors for the decoding process\n\n\tthe command :\t%s -dni file5 keyfile2\n\n\tlets you choose between crypting or decrypting, will prompt for a password that crypt/decrypt the file but generates the substitution's tables with the keyfile passing only one cycle of the Fisher & Yates algorythm(option 'n', so it's shorter in time), inverts the scrambling phase with the xoring phase(option 'i') and write on top of the source file(option 'd')\n\n\tthe command :\t%s -k file6\n\n\tgenerate a keyfile and use it to crypt/decrypt the file\n\n\tthe command :\t%s --keyfile\n\n\tonly generate a keyfile and put it in the current directory\n\nBUGS\n\tIn rare cases, when crypting/decrypting from a directory, the system cannot open the tarfile it created from the directory (possibly the file system is too slow to register it). That's why the program waits one second after the creation of the tarfile when sourcefile is a directory. If it is not enough, the tarfile will not be deleted and you just have to redo the same command with the tarfile as the source file instead of the directory (you can use the d option to securely delete the tarfile to produce the same steps as the standard case).\n\nAUTHOR\n\tPierre-François MONVILLE\n\nCOPYRIGHT\n\tMIT <12 september 2015> <Pierre-François MONVILLE>\n\n", progName, progName, progName, progName, progName, progName, progName, progName, progName, progName);
160160
} else{
161161
fprintf(dest,
162-
"\n%s -- crypt or decrypt any data\n\nVersion : 3.6.4\n\nUsage : %s [options] FILE|DIRECTORY [KEYFILE]\n\nFILE|DIRECTORY :\tpath to the file or directory to crypt/decrypt\n\nKEYFILE :\t\tpath to a keyfile for the substitution's table\n\nOptions :\n -h | --help :\t\tfurther help\n -k | --keyfile :\tgenerate keyfile\n -s (simple) :\t\tput the scrambler off\n -i (inverted) :\tinvert the process, swapping xor with scramble\n -n (normalised) :\tnormalise the size of the keyfile\n -d (destroy) :\toverwrite source file or delete source folder afterwards\n -f (force) :\t\tnever ask, overwrite existing files\n -r (randomize) :\trandomize the name of the output file, keeping extension\n -R (full randomize) : randomize the name of the output file, no extension\n\n", progName, progName);
162+
"\n%s -- crypt or decrypt any data\n\nVersion : 3.6.6\n\nUsage : %s [options] FILE|DIRECTORY [KEYFILE]\n\nFILE|DIRECTORY :\tpath to the file or directory to crypt/decrypt\n\nKEYFILE :\t\tpath to a keyfile for the substitution's table\n\nOptions :\n -h | --help :\t\tfurther help\n -k | --keyfile :\tgenerate keyfile\n -s (simple) :\t\tput the scrambler off\n -i (inverted) :\tinvert the process, swapping xor with scramble\n -n (normalised) :\tnormalise the size of the keyfile\n -d (destroy) :\toverwrite source file or delete source folder afterwards\n -f (force) :\t\tnever ask, overwrite existing files\n -r (randomize) :\trandomize the name of the output file, keeping extension\n -R (full randomize) : randomize the name of the output file, no extension\n\n", progName, progName);
163163
}
164164
exit(status);
165165
}
@@ -340,7 +340,7 @@ char* processTarString(char* string){
340340
void fillWithSpaces(char* string, int size, int numberOfSpaces){
341341
struct winsize windowSize;
342342
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
343-
char toFill;
343+
int toFill;
344344
if(numberOfSpaces - (windowSize.ws_col - strlen(string)) > 0){
345345
toFill = windowSize.ws_col - strlen(string) -1;
346346
}else{
@@ -716,7 +716,7 @@ void scramble(FILE* keyFile){
716716
char temp = 0;
717717
// adjust loadbar to display width
718718
struct winsize windowSize;
719-
char spaceLeft;
719+
int spaceLeft;
720720
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
721721
spaceLeft = windowSize.ws_col - 65;
722722
if(spaceLeft < 3){
@@ -992,7 +992,7 @@ static inline void loadBar(int currentIteration, int maximalIteration, int numbe
992992

993993
// adjust loadbar to display width
994994
struct winsize windowSize;
995-
char numberOfSegments;
995+
int numberOfSegments;
996996
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
997997
numberOfSegments = windowSize.ws_col - 45;
998998
if(numberOfSegments < 4){
@@ -1366,7 +1366,7 @@ void checkArguments(int numberOfArgument, char* secondArgument){
13661366
*/
13671367
void checkDisplaySize(){
13681368
struct winsize windowSize;
1369-
char numberOfSegments;
1369+
int numberOfSegments;
13701370
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
13711371

13721372
numberOfSegments = windowSize.ws_col - 45;
@@ -1984,15 +1984,13 @@ void startMainProcess(FILE* mainFile, char wantsToDeleteFirstFile, char wantsToR
19841984
char message[100];
19851985
sprintf(message, "Starting encryption... Done");
19861986
fillWithSpaces(message,100, 67);
1987-
// printf("\rstarting encryption... Done \n");
19881987
printf("\r%s\n", message);
19891988
}
19901989
else{
19911990
decode(mainFile, wantsToDeleteFirstFile, "Starting decryption... ");
19921991
char message[100];
19931992
sprintf(message, "Starting decryption... Done");
19941993
fillWithSpaces(message,100, 67);
1995-
// printf("\rstarting decryption... Done \n");
19961994
printf("\r%s\n", message);
19971995
}
19981996
fflush(stdout);

0 commit comments

Comments
 (0)