Skip to content

Commit 0030ea8

Browse files
authored
fix potential size_t overflow in twin serializer (#2567)
1 parent 063c235 commit 0030ea8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎serializer/inc/serializer_devicetwin.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
static void serializer_ingest(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback)
1818
{
1919
/*by convention, userContextCallback is a pointer to a model instance created with CodeFirst_CreateDevice*/
20-
21-
char* copyOfPayload = (char*)malloc(size + 1);
20+
size_t sizeToAllocate = size + 1;
21+
if (sizeToAllocate == 0)
22+
{
23+
LogError("Payload size exceeds maximum allocation\n");
24+
return;
25+
}
26+
char* copyOfPayload = (char*)malloc(sizeToAllocate);
2227
if (copyOfPayload == NULL)
2328
{
2429
LogError("unable to malloc\n");

0 commit comments

Comments
 (0)