From f5a6ece798a4dce368ebf39879d954f85fdc6198 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 9 Dec 2022 15:56:48 +0100 Subject: [PATCH] made decrypter's using TEXT parameter safe It was changing the original TEXT before... I'm so dumb... --- src/core/lib/decrypter.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index 9798904..a580992 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -65,14 +65,19 @@ outputFlags decryptText(char *text, char *keyNew) int *textKeyChain; char *key = malloc(strlen(keyNew) + 1); int *encryptedTextKeyChain; + char *usedText = malloc(strlen(text) + 1); + char *usedTextCopy = usedText; //COPY keyNew TO key strcpy(key, keyNew); + //COPY text TO usedText + strcpy(usedText, text); + //GET LENGTH OF returningText AND textKeyChain - for (int i = 0; i < (int) strlen(text); i++) + for (int i = 0; i < (int) strlen(usedText); i++) { - if (text[i] == getEncryptionSeparator()) numberBuffer++; + if (usedText[i] == getEncryptionSeparator()) numberBuffer++; } //SET LENGTH (numberBuffer) @@ -90,9 +95,9 @@ outputFlags decryptText(char *text, char *keyNew) numberBuffer = 0; //GET LENGTH OF EACH CHARACTER - for (int j = 0; j < (int) strlen(text); j++) + for (int j = 0; j < (int) strlen(usedText); j++) { - if (text[j] == getEncryptionSeparator()) break; + if (usedText[j] == getEncryptionSeparator()) break; numberBuffer++; } @@ -112,16 +117,16 @@ outputFlags decryptText(char *text, char *keyNew) } //LOAD textBuffer - for (int j = 0; j < (int) strlen(text); j++) + for (int j = 0; j < (int) strlen(usedText); j++) { - textBuffer[j] = text[j]; + textBuffer[j] = usedText[j]; if (numberBuffer == j) break; } encryptedTextKeyChain[i] = atoi(textBuffer); - text += numberBuffer + 1; + usedText += numberBuffer + 1; } //DECRYPT TEXT @@ -160,6 +165,7 @@ outputFlags decryptText(char *text, char *keyNew) free(textKeyChain); free(encryptedTextKeyChain); free(textBuffer); + free(usedTextCopy); return output; }