Re #1882 (misc): Add checking before calling pj_strncpy(), to make it more robust and consistent with the other two checks below.

Note that without the check, it should be safe, but the buffer could point to one byte after the buffer, even though the string length is zero.

Thanks to Dusan Klinec for the proposed patch.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@5224 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Sauw Ming 2015-12-30 23:52:54 +00:00
parent 52b25f01f1
commit e005b0f86d
1 changed files with 7 additions and 3 deletions

View File

@ -249,9 +249,13 @@ PJ_DEF(pj_status_t) pjsua_buddy_get_info( pjsua_buddy_id buddy_id,
total += info->uri.slen;
/* contact */
info->contact.ptr = info->buf_ + total;
pj_strncpy(&info->contact, &buddy->contact, sizeof(info->buf_)-total);
total += info->contact.slen;
if (total < sizeof(info->buf_)) {
info->contact.ptr = info->buf_ + total;
pj_strncpy(&info->contact, &buddy->contact, sizeof(info->buf_) - total);
total += info->contact.slen;
} else {
info->contact = pj_str("");
}
/* Presence status */
pj_memcpy(&info->pres_status, &buddy->status, sizeof(pjsip_pres_status));