[PATCH 4.4 32/56] Bluetooth: hidp: Fix handling of strncpy for hid->name information

From: Greg Kroah-Hartman
Date: Mon Sep 17 2018 - 18:50:10 EST


4.4-stable review patch. If anyone has any objections, please let me know.

------------------

From: Marcel Holtmann <marcel@xxxxxxxxxxxx>

[ Upstream commit b3cadaa485f0c20add1644a5c877b0765b285c0c ]

This fixes two issues with setting hid->name information.

CC net/bluetooth/hidp/core.o
In function âhidp_setup_hidâ,
inlined from âhidp_session_dev_initâ at net/bluetooth/hidp/core.c:815:9,
inlined from âhidp_session_newâ at net/bluetooth/hidp/core.c:953:8,
inlined from âhidp_connection_addâ at net/bluetooth/hidp/core.c:1366:8:
net/bluetooth/hidp/core.c:778:2: warning: âstrncpyâ output may be truncated copying 127 bytes from a string of length 127 [-Wstringop-truncation]
strncpy(hid->name, req->name, sizeof(req->name) - 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CC net/bluetooth/hidp/core.o
net/bluetooth/hidp/core.c: In function âhidp_setup_hidâ:
net/bluetooth/hidp/core.c:778:38: warning: argument to âsizeofâ in âstrncpyâ call is the same expression as the source; did you mean to use the size of the destination? [-Wsizeof-pointer-memaccess]
strncpy(hid->name, req->name, sizeof(req->name));
^

Signed-off-by: Marcel Holtmann <marcel@xxxxxxxxxxxx>
Signed-off-by: Johan Hedberg <johan.hedberg@xxxxxxxxx>
Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
net/bluetooth/hidp/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -774,7 +774,7 @@ static int hidp_setup_hid(struct hidp_se
hid->version = req->version;
hid->country = req->country;

- strncpy(hid->name, req->name, sizeof(req->name) - 1);
+ strncpy(hid->name, req->name, sizeof(hid->name));

snprintf(hid->phys, sizeof(hid->phys), "%pMR",
&l2cap_pi(session->ctrl_sock->sk)->chan->src);