From 28d707662b11c120e21697c3f1b208cdf7c6d0b2 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 12 Mar 2015 13:11:28 -0400 Subject: Fixed tox_new issue. --- toxcore/tox.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toxcore/tox.c b/toxcore/tox.c index cc507a65..e99f7a75 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -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; @@ -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); -- cgit v1.2.3