Skip to content

Commit e9627cf

Browse files
nattgrishefloryd
authored andcommitted
Fix multiple data corruption in OD load
If the current OD had an object with a larger data size than when the objects were stored, only the smaller part of the uint64_t would be read into, but the actual setting of the object would use the entire, partly uninitialized, value. Also, in the pointer case the size was not checked against the actual size of the target object, which would cause memory corruption if the object had been shrunk since the values were stored. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@unjo.com> Change-Id: I1e0fc0b0d6da4594ca8bcb61e01ab6ab5f42a551
1 parent 5ab1a5e commit e9627cf

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/co_od.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ uint32_t co_od_load (co_net_t * net, co_store_t store)
374374
uint16_t index;
375375
uint8_t subindex;
376376
size_t size;
377-
uint64_t value;
377+
uint64_t value = 0;
378378
uint8_t * ptr;
379379
uint32_t abort;
380380

@@ -398,7 +398,14 @@ uint32_t co_od_load (co_net_t * net, co_store_t store)
398398
if (entry == NULL || !(entry->flags & OD_WRITE))
399399
continue;
400400

401-
if (size > sizeof (value))
401+
if (size <= sizeof (value))
402+
{
403+
if (net->read (arg, &value, size) < 0)
404+
goto error;
405+
406+
co_od_set_value (net, obj, entry, subindex, value);
407+
}
408+
else if (size == CO_BYTELENGTH (entry->bitlength))
402409
{
403410
/* Get pointer to storage */
404411
abort = co_od_get_ptr (net, obj, entry, subindex, &ptr);
@@ -410,10 +417,16 @@ uint32_t co_od_load (co_net_t * net, co_store_t store)
410417
}
411418
else
412419
{
420+
/* Stored size does not match object size. Discard data. */
421+
while (size > sizeof(value))
422+
{
423+
if (net->read (arg, &value, sizeof (value)) < 0)
424+
goto error;
425+
size -= sizeof(value);
426+
}
427+
413428
if (net->read (arg, &value, size) < 0)
414429
goto error;
415-
416-
co_od_set_value (net, obj, entry, subindex, value);
417430
}
418431
}
419432

0 commit comments

Comments
 (0)