Skip to content

Commit 828063f

Browse files
committed
usb: uvc: respect setup->wLength in responses
In some cases, setup->wLength is shorter than the allocated buffer size. This lead to responses larger than what the host requested, which it rejected. Fix it by using the minimum between the allocated size, the struct size, and the wLength requested. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 26cb178 commit 828063f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

subsys/usb/device_next/class/usbd_uvc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ static int uvc_get_vs_probe(const struct device *dev, struct net_buf *const buf,
694694
const struct usb_setup_packet *const setup)
695695
{
696696
struct uvc_data *data = dev->data;
697-
const size_t size = MIN(sizeof(struct uvc_probe), net_buf_tailroom(buf));
697+
const size_t size = MIN(net_buf_tailroom(buf),
698+
MIN(sizeof(struct uvc_probe), setup->wLength));
698699
struct uvc_probe probe = {0};
699700
int ret;
700701

@@ -912,7 +913,8 @@ static int uvc_get_vc_ctrl(const struct device *dev, struct net_buf *const buf,
912913
const struct device *video_dev = data->video_dev;
913914
struct video_ctrl_query cq = {.id = map->cid, .dev = video_dev};
914915
struct video_control ctrl = {.id = map->cid};
915-
size_t size = MIN(setup->wLength, net_buf_tailroom(buf));
916+
const size_t size = MIN(net_buf_tailroom(buf),
917+
MIN(sizeof(struct uvc_probe), setup->wLength));
916918
int64_t val64;
917919
int ret;
918920

@@ -1104,7 +1106,8 @@ static int uvc_get_errno(const struct device *dev, struct net_buf *const buf,
11041106
const struct usb_setup_packet *const setup)
11051107
{
11061108
struct uvc_data *data = dev->data;
1107-
size_t size = MIN(setup->wLength, net_buf_tailroom(buf));
1109+
const size_t size = MIN(net_buf_tailroom(buf),
1110+
MIN(sizeof(struct uvc_probe), setup->wLength));
11081111

11091112
switch (setup->bRequest) {
11101113
case UVC_GET_INFO:

0 commit comments

Comments
 (0)