Add some size checks on the server to ensure received data matches the size from the packet header

This commit is contained in:
Adam Honse 2024-07-26 00:19:19 -05:00
parent 215ae6118a
commit 64a0d2c061

View file

@ -682,11 +682,18 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break;
}
/*---------------------------------------------------------*\
| Verify the color description size (first 4 bytes of data) |
| matches the packet size in the header |
\*---------------------------------------------------------*/
if(header.pkt_size == *((unsigned int*)data))
{
if(header.pkt_dev_idx < controllers.size())
{
controllers[header.pkt_dev_idx]->SetColorDescription((unsigned char *)data);
controllers[header.pkt_dev_idx]->UpdateLEDs();
}
}
break;
case NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS:
@ -695,6 +702,12 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break;
}
/*---------------------------------------------------------*\
| Verify the color description size (first 4 bytes of data) |
| matches the packet size in the header |
\*---------------------------------------------------------*/
if(header.pkt_size == *((unsigned int*)data))
{
if(header.pkt_dev_idx < controllers.size())
{
int zone;
@ -704,6 +717,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
controllers[header.pkt_dev_idx]->SetZoneColorDescription((unsigned char *)data);
controllers[header.pkt_dev_idx]->UpdateZoneLEDs(zone);
}
}
break;
case NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED:
@ -712,6 +726,12 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break;
}
/*---------------------------------------------------------*\
| Verify the single LED color description size (8 bytes) |
| matches the packet size in the header |
\*---------------------------------------------------------*/
if(header.pkt_size == (sizeof(int) + sizeof(RGBColor)))
{
if(header.pkt_dev_idx < controllers.size())
{
int led;
@ -721,6 +741,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
controllers[header.pkt_dev_idx]->SetSingleLEDColorDescription((unsigned char *)data);
controllers[header.pkt_dev_idx]->UpdateSingleLED(led);
}
}
break;
case NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE:
@ -736,11 +757,18 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break;
}
/*---------------------------------------------------------*\
| Verify the mode description size (first 4 bytes of data) |
| matches the packet size in the header |
\*---------------------------------------------------------*/
if(header.pkt_size == *((unsigned int*)data))
{
if(header.pkt_dev_idx < controllers.size())
{
controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data, client_info->client_protocol_version);
controllers[header.pkt_dev_idx]->UpdateMode();
}
}
break;
case NET_PACKET_ID_RGBCONTROLLER_SAVEMODE:
@ -749,11 +777,18 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break;
}
/*---------------------------------------------------------*\
| Verify the mode description size (first 4 bytes of data) |
| matches the packet size in the header |
\*---------------------------------------------------------*/
if(header.pkt_size == *((unsigned int*)data))
{
if(header.pkt_dev_idx < controllers.size())
{
controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data, client_info->client_protocol_version);
controllers[header.pkt_dev_idx]->SaveMode();
}
}
break;
case NET_PACKET_ID_REQUEST_PROFILE_LIST: