checking for invalid base64 in read_socket_raw
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 29s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 3m24s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m19s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m56s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m11s

This commit is contained in:
Václav Šmejkal 2025-02-04 20:00:14 +01:00
parent 429e0cfeaa
commit 4e04b89221
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 16 additions and 2 deletions

View File

@ -133,6 +133,10 @@ char *why2_chat_base64_decode(char *encoded_message, size_t *length)
BIO *bio; BIO *bio;
BIO *b64; BIO *b64;
char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER
//INVALID BASE64
if (separator_ptr == NULL) return NULL;
size_t length_local = strtoull(separator_ptr + 1, NULL, 10); size_t length_local = strtoull(separator_ptr + 1, NULL, 10);
char* decoded_message = why2_malloc(length_local + 1); char* decoded_message = why2_malloc(length_local + 1);
int decoded_length; int decoded_length;

View File

@ -168,6 +168,8 @@ why2_bool is_ascii(char c)
void remove_non_ascii(char **text) void remove_non_ascii(char **text)
{ {
if (*text == NULL) return;
//REMOVE NON ASCII CHARS //REMOVE NON ASCII CHARS
int j = 0; int j = 0;
for (int i = 0; (*text)[i] != '\0'; i++) for (int i = 0; (*text)[i] != '\0'; i++)
@ -217,6 +219,14 @@ void encrypt_decrypt_message(char **message, char *key, enum ENCRYPTION_DECRYPTI
size_t length = strlen(*message); size_t length = strlen(*message);
char *message_decoded = base64_before_cb(*message, &length); char *message_decoded = base64_before_cb(*message, &length);
//INVALID MESSAGE RECEIVED
if (message_decoded == NULL)
{
why2_deallocate(*message);
*message = NULL;
return;
}
//SET FLAGS //SET FLAGS
if (why2_get_key_length() < strlen(key)) why2_set_key_length(strlen(key)); if (why2_get_key_length() < strlen(key)) why2_set_key_length(strlen(key));
why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 0 }); //TODO: Add padding why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 0 }); //TODO: Add padding
@ -332,8 +342,8 @@ char *read_socket_raw(int socket, char *key)
//REMOVE NON-ASCII //REMOVE NON-ASCII
remove_non_ascii(&output); remove_non_ascii(&output);
//VALIDATE JSON FORMAT //VALIDATE JSON FORMAT (AUTOMATICALLY FAIL IF output IS NULL)
struct json_object *json = json_tokener_parse(output); struct json_object *json = output == NULL ? NULL : json_tokener_parse(output);
if (json == NULL) if (json == NULL)
{ {
//RESET output //RESET output