diff options
author | irungentoo <irungentoo@gmail.com> | 2013-11-12 12:50:54 -0800 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-11-12 12:50:54 -0800 |
commit | 62125ce90fdb7c184430636475449f5c33fd1159 (patch) | |
tree | 6e2c3ff83dae4358a161bbb0b92b2d34c2346298 /toxcore/Messenger.c | |
parent | 18c98eb87d43beac9191d80f8fa0657398ecee4b (diff) | |
parent | e457eb6635b29b29886420f7041ff5d137e6b0ce (diff) |
Merge pull request #645 from FullName/nTox-patches
nTox: enforce friend name null termination, reduce memory loss, allow nickchange as oldname=>newname
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 659c837b..66faa4db 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1539,12 +1539,15 @@ void do_friends(Messenger *m) | |||
1539 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) | 1539 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) |
1540 | break; | 1540 | break; |
1541 | 1541 | ||
1542 | memcpy(m->friendlist[i].name, data, data_length); | 1542 | /* Make sure the NULL terminator is present. */ |
1543 | m->friendlist[i].name_length = data_length; | 1543 | data[data_length - 1] = 0; |
1544 | m->friendlist[i].name[data_length - 1] = 0; /* Make sure the NULL terminator is present. */ | ||
1545 | 1544 | ||
1545 | /* inform of namechange before we overwrite the old name */ | ||
1546 | if (m->friend_namechange) | 1546 | if (m->friend_namechange) |
1547 | m->friend_namechange(m, i, m->friendlist[i].name, data_length, m->friend_namechange_userdata); | 1547 | m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata); |
1548 | |||
1549 | memcpy(m->friendlist[i].name, data, data_length); | ||
1550 | m->friendlist[i].name_length = data_length; | ||
1548 | 1551 | ||
1549 | break; | 1552 | break; |
1550 | } | 1553 | } |