Skip to content

Commit

Permalink
Fixed tox_new issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
irungentoo committed Mar 12, 2015
1 parent 7afab00 commit 28d7076
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion toxcore/tox.c
Expand Up @@ -99,6 +99,11 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng
}

if (data) {
if (length < TOX_ENC_SAVE_MAGIC_LENGTH) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
return NULL;
}

if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED);
return NULL;
Expand Down Expand Up @@ -169,7 +174,7 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng
return NULL;
}

if (messenger_load(m, data, length) == -1) {
if (data && length && messenger_load(m, data, length) == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
} else {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
Expand Down

0 comments on commit 28d7076

Please sign in to comment.