Merge pull request #473 from fhahn/check-realloc-return-value

Check return value of realloc_friendlist and return FAERR_NOMEM on error
This commit is contained in:
irungentoo 2013-08-15 09:32:05 -07:00
commit bf0c2364e1
2 changed files with 9 additions and 3 deletions

View File

@ -120,6 +120,7 @@ void getaddress(Messenger *m, uint8_t *address)
* return FAERR_BADCHECKSUM if bad checksum in address * return FAERR_BADCHECKSUM if bad checksum in address
* return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different
* (the nospam for that friend was set to the new one) * (the nospam for that friend was set to the new one)
* return FAERR_NOMEM if increasing the friend list size fails
*/ */
int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
{ {
@ -148,7 +149,8 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
} }
/* resize the friend list if necessary */ /* resize the friend list if necessary */
realloc_friendlist(m, m->numfriends + 1); if (realloc_friendlist(m, m->numfriends + 1) != 0)
return FAERR_NOMEM;
uint32_t i; uint32_t i;
for (i = 0; i <= m->numfriends; ++i) { for (i = 0; i <= m->numfriends; ++i) {
@ -180,7 +182,8 @@ int m_addfriend_norequest(Messenger *m, uint8_t * client_id)
return -1; return -1;
/* resize the friend list if necessary */ /* resize the friend list if necessary */
realloc_friendlist(m, m->numfriends + 1); if (realloc_friendlist(m, m->numfriends + 1) != 0)
return FAERR_NOMEM;
uint32_t i; uint32_t i;
for (i = 0; i <= m->numfriends; ++i) { for (i = 0; i <= m->numfriends; ++i) {
@ -221,7 +224,9 @@ int m_delfriend(Messenger *m, int friendnumber)
break; break;
} }
m->numfriends = i; m->numfriends = i;
realloc_friendlist(m, m->numfriends + 1);
if (realloc_friendlist(m, m->numfriends + 1) != 0)
return FAERR_NOMEM;
return 0; return 0;
} }

View File

@ -63,6 +63,7 @@ extern "C" {
#define FAERR_UNKNOWN -5 #define FAERR_UNKNOWN -5
#define FAERR_BADCHECKSUM -6 #define FAERR_BADCHECKSUM -6
#define FAERR_SETNEWNOSPAM -7 #define FAERR_SETNEWNOSPAM -7
#define FAERR_NOMEM -8
/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased /* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
to an absurdly large number later */ to an absurdly large number later */