Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actually check for errors when encryting the tox save file #576

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions jni-c-toxcore/jni-c-toxcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,11 @@ Tox *create_tox(int udp_enabled, int orbot_enabled, const char *proxy_host, uint

void update_savedata_file(const Tox *tox, const uint8_t *passphrase, size_t passphrase_len)
{
if (tox == NULL)
{
dbg(9, "update_savedata_file:ERROR:tox ptr is NULL");
return;
}
size_t size = tox_get_savedata_size(tox);
// dbg(9, "update_savedata_file:tox_get_savedata_size=%d", (int)size);

Expand All @@ -824,6 +829,12 @@ void update_savedata_file(const Tox *tox, const uint8_t *passphrase, size_t pass

char *savedata = calloc(1, size);
// dbg(9, "update_savedata_file:savedata=%p", savedata);
if (tox == NULL)
{
dbg(9, "update_savedata_file:ERROR:tox ptr is NULL");
free(savedata);
return;
}
tox_get_savedata(tox, (uint8_t *)savedata);
char *full_path_filename = calloc(1, MAX_FULL_PATH_LENGTH);

Expand All @@ -847,12 +858,12 @@ void update_savedata_file(const Tox *tox, const uint8_t *passphrase, size_t pass
// dbg(9, "update_savedata_file:savedata_enc=%p", savedata_enc);
TOX_ERR_ENCRYPTION error;
tox_pass_encrypt((const uint8_t *)savedata, size, passphrase, passphrase_len, savedata_enc, &error);
// dbg(9, "update_savedata_file:tox_pass_encrypt:%d", (int)error);
dbg(9, "update_savedata_file:tox_pass_encrypt:%d", (int)error);
bool res = false;

if(size_enc < TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
if ((size_enc < TOX_PASS_ENCRYPTION_EXTRA_LENGTH) || (error != TOX_ERR_ENCRYPTION_OK))
{
dbg(9, "update_savedata_file:ERROR:size_enc < TOX_PASS_ENCRYPTION_EXTRA_LENGTH");
dbg(9, "update_savedata_file:ERROR:size_enc < TOX_PASS_ENCRYPTION_EXTRA_LENGTH or error != TOX_ERR_ENCRYPTION_OK");
if(savedata)
{
free(savedata);
Expand Down
Loading