Skip to content

Commit

Permalink
Bluetooth: hidp: NUL terminate a string in the compat ioctl
Browse files Browse the repository at this point in the history
This change is similar to commit a1616a5 ("Bluetooth: hidp: fix
buffer overflow") but for the compat ioctl.  We take a string from the
user and forgot to ensure that it's NUL terminated.

I have also changed the strncpy() in to strscpy() in hidp_setup_hid().
The difference is the strncpy() doesn't necessarily NUL terminate the
destination string.  Either change would fix the problem but it's nice
to take a belt and suspenders approach and do both.

Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: Marcel Holtmann <[email protected]>
  • Loading branch information
Dan Carpenter authored and holtmann committed Jul 6, 2019
1 parent 44d34af commit dcae905
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion net/bluetooth/hidp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ static int hidp_setup_hid(struct hidp_session *session,
hid->version = req->version;
hid->country = req->country;

strncpy(hid->name, req->name, sizeof(hid->name));
strscpy(hid->name, req->name, sizeof(hid->name));

snprintf(hid->phys, sizeof(hid->phys), "%pMR",
&l2cap_pi(session->ctrl_sock->sk)->chan->src);
Expand Down
1 change: 1 addition & 0 deletions net/bluetooth/hidp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ static int hidp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigne
ca.version = ca32.version;
ca.flags = ca32.flags;
ca.idle_to = ca32.idle_to;
ca32.name[sizeof(ca32.name) - 1] = '\0';
memcpy(ca.name, ca32.name, 128);

csock = sockfd_lookup(ca.ctrl_sock, &err);
Expand Down

0 comments on commit dcae905

Please sign in to comment.