Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usbus: check received setup request data amount #17203

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sys/usb/usbus/cdc/acm/cdc_acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ static int _control_handler(usbus_t *usbus, usbus_handler_t *handler,
DEBUG("CDCACM: line coding not supported\n");
return -1;
}
if ((state == USBUS_CONTROL_REQUEST_STATE_OUTDATA) &&
(setup->length == sizeof(usb_req_cdcacm_coding_t))) {
if (setup->length != sizeof(usb_req_cdcacm_coding_t)) {
return -1; /* Incorrect amount of data expected */
}
if (state == USBUS_CONTROL_REQUEST_STATE_OUTDATA) {
size_t len = 0;
usb_req_cdcacm_coding_t *coding =
(usb_req_cdcacm_coding_t*)usbus_control_get_out_data(usbus,
Expand Down
28 changes: 17 additions & 11 deletions sys/usb/usbus/usbus_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,24 @@ static void _recv_setup(usbus_t *usbus, usbus_control_handler_t *handler)

DEBUG("usbus_control: Received setup %x %x @ %d\n", pkt->type,
pkt->request, pkt->length);

uint8_t destination = pkt->type & USB_SETUP_REQUEST_RECIPIENT_MASK;
int res = 0;
switch (destination) {
case USB_SETUP_REQUEST_RECIPIENT_DEVICE:
res = _recv_dev_setup(usbus, pkt);
break;
case USB_SETUP_REQUEST_RECIPIENT_INTERFACE:
res = _recv_interface_setup(usbus, pkt);
break;
default:
DEBUG("usbus_control: Unhandled setup request\n");

/* If write and length is more than expected */
if (!(usb_setup_is_read(pkt)) && (handler->received_len > pkt->length)) {
res = -1; /* Stall */
}
else {
uint8_t destination = pkt->type & USB_SETUP_REQUEST_RECIPIENT_MASK;
switch (destination) {
case USB_SETUP_REQUEST_RECIPIENT_DEVICE:
res = _recv_dev_setup(usbus, pkt);
break;
case USB_SETUP_REQUEST_RECIPIENT_INTERFACE:
res = _recv_interface_setup(usbus, pkt);
break;
default:
DEBUG("usbus_control: Unhandled setup request\n");
}
}
if (res < 0) {
/* Signal stall to indicate unsupported (USB 2.0 spec 9.6.2 */
Expand Down