From 8b60cdc81b86a5e8f5ccf073a49af9dad097a0d7 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Sun, 21 Jul 2024 23:43:52 +0200 Subject: [PATCH] change add_logininfo_to_buffer to accept size of data for future use --- include/func.hpp | 2 +- source/arg_func.cpp | 6 +++--- source/func.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/func.hpp b/include/func.hpp index 073ec47..854a2f7 100644 --- a/include/func.hpp +++ b/include/func.hpp @@ -30,7 +30,7 @@ int find_logininfo_in_buffer(Buffer &buffer, const char *label); void delete_logininfo_from_buffer(Buffer &buffer, int index_of_pass); -void add_logininfo_to_buffer(Buffer &buffer, const char *label, const char *username, const char *password); +void add_logininfo_to_buffer(Buffer &buffer, const char *label, size_t label_size, const char *username, size_t username_size, const char *password, size_t password_size); LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer &buffer, int index_of_pass); diff --git a/source/arg_func.cpp b/source/arg_func.cpp index 8b7bb8b..e160184 100644 --- a/source/arg_func.cpp +++ b/source/arg_func.cpp @@ -159,7 +159,7 @@ std::optional arg_new_password(Buffer &decrypted_buffer, Buffe } } - add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str()); + add_logininfo_to_buffer(decrypted_buffer, name.c_str(), name.size(), username.c_str(), username.size(), password.c_str(), password.size()); Aes256::encrypt(key, decrypted_buffer, encrypted_buffer); encrypted_buffer.save_to_file(); Index *index = (Index *)decrypted_buffer.buffer; @@ -184,7 +184,7 @@ void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char std::getline(std::cin, username); delete_logininfo_from_buffer(decrypted_buffer, pass); - add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str()); + add_logininfo_to_buffer(decrypted_buffer, name.c_str(), name.size(), username.c_str(), username.size(), password.c_str(), password.size()); Aes256::encrypt(key, decrypted_buffer, encrypted_buffer); encrypted_buffer.save_to_file(); } @@ -208,7 +208,7 @@ void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const ch std::getline(std::cin, name); delete_logininfo_from_buffer(decrypted_buffer, pass); - add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str()); + add_logininfo_to_buffer(decrypted_buffer, name.c_str(), name.size(), username.c_str(), username.size(), password.c_str(), password.size()); Aes256::encrypt(key, decrypted_buffer, encrypted_buffer); encrypted_buffer.save_to_file(); } diff --git a/source/func.cpp b/source/func.cpp index 4d35e45..c745b26 100644 --- a/source/func.cpp +++ b/source/func.cpp @@ -48,11 +48,11 @@ void delete_logininfo_from_buffer(Buffer &buffer, int index_of_pass) in_index->offset -= sizeof(LoginInfo); } -void add_logininfo_to_buffer(Buffer &buffer, const char *label, const char *username, const char *password) +void add_logininfo_to_buffer(Buffer &buffer, const char *label, size_t label_size, const char *username, size_t username_size, const char *password, size_t password_size) { - uint32_t label_start = buffer.add_end((uint8_t *)label, strlen(label) + 1); - uint32_t username_start = buffer.add_end((uint8_t *)username, strlen(username) + 1); - uint32_t password_start = buffer.add_end((uint8_t *)password, strlen(password) + 1); + uint32_t label_start = buffer.add_end((uint8_t *)label, label_size + 1); + uint32_t username_start = buffer.add_end((uint8_t *)username, username_size + 1); + uint32_t password_start = buffer.add_end((uint8_t *)password, password_size + 1); Index *index = (Index *)buffer.buffer;