mirror of
https://github.com/xemu-project/xemu.git
synced 2025-03-04 02:29:17 +00:00
bt: replace fragile snprintf use and unwarranted strncpy
In bt_hci_name_req a failed snprintf could return len larger than sizeof(params.name), which means the following memset call would have a "length" value of (size_t)-1, -2, etc... Sounds scary. But currently, one can deduce that there is no problem: strlen(slave->lmp_name) is guaranteed to be smaller than CHANGE_LOCAL_NAME_CP_SIZE, which is the same as sizeof(params.name), so this cannot happen. Regardless, there is no justification for using snprintf+memset. Use pstrcpy instead. Also, in bt_hci_event_complete_read_local_name, use pstrcpy in place of unwarranted strncpy. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
5847d9e139
commit
e5fda03839
@ -943,7 +943,6 @@ static int bt_hci_name_req(struct bt_hci_s *hci, bdaddr_t *bdaddr)
|
||||
{
|
||||
struct bt_device_s *slave;
|
||||
evt_remote_name_req_complete params;
|
||||
int len;
|
||||
|
||||
for (slave = hci->device.net->slave; slave; slave = slave->next)
|
||||
if (slave->page_scan && !bacmp(&slave->bd_addr, bdaddr))
|
||||
@ -955,9 +954,7 @@ static int bt_hci_name_req(struct bt_hci_s *hci, bdaddr_t *bdaddr)
|
||||
|
||||
params.status = HCI_SUCCESS;
|
||||
bacpy(¶ms.bdaddr, &slave->bd_addr);
|
||||
len = snprintf(params.name, sizeof(params.name),
|
||||
"%s", slave->lmp_name ?: "");
|
||||
memset(params.name + len, 0, sizeof(params.name) - len);
|
||||
pstrcpy(params.name, sizeof(params.name), slave->lmp_name ?: "");
|
||||
bt_hci_event(hci, EVT_REMOTE_NAME_REQ_COMPLETE,
|
||||
¶ms, EVT_REMOTE_NAME_REQ_COMPLETE_SIZE);
|
||||
|
||||
@ -1388,7 +1385,7 @@ static inline void bt_hci_event_complete_read_local_name(struct bt_hci_s *hci)
|
||||
params.status = HCI_SUCCESS;
|
||||
memset(params.name, 0, sizeof(params.name));
|
||||
if (hci->device.lmp_name)
|
||||
strncpy(params.name, hci->device.lmp_name, sizeof(params.name));
|
||||
pstrcpy(params.name, sizeof(params.name), hci->device.lmp_name);
|
||||
|
||||
bt_hci_event_complete(hci, ¶ms, READ_LOCAL_NAME_RP_SIZE);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user