Skip to content

Commit

Permalink
actually check for errors when encryting the tox save file
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jan 8, 2025
1 parent d05b090 commit 8e1e4ad
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 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,15 @@ 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");
if(savedata)
{
free(savedata);
}
return;
}
tox_get_savedata(tox, (uint8_t *)savedata);
char *full_path_filename = calloc(1, MAX_FULL_PATH_LENGTH);

Expand All @@ -847,12 +861,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

0 comments on commit 8e1e4ad

Please sign in to comment.