Skip to content

Commit e2494e3

Browse files
nattgrishefloryd
authored andcommitted
Fix corrupt OD load following a non-existent object
If an OD is loaded from a store that contains an object which has subsequently been removed, it is necessary to skip the part of the data which was stored for the object. Otherwise the data part will be interpreted as the index, subindex and size of the next object to load, possibly loading incorrect data or at least failing to load the following objects. Also skip the object if the current OD would not store it (OD_TRANSIENT) and also abort the load if a size of zero is encountered in the store. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@unjo.com>
1 parent ca4688e commit e2494e3

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/co_od.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,19 @@ uint32_t co_od_load (co_net_t * net, co_store_t store)
384384
if (net->read (arg, &subindex, sizeof (subindex)) < 0)
385385
goto error;
386386

387-
if (net->read (arg, &size, sizeof (size)) < 0)
387+
if (net->read (arg, &size, sizeof (size)) < 0 || size == 0)
388388
goto error;
389389

390390
/* Attempt to set value. Errors are ignored to support firmware
391391
update of dictionary */
392392

393393
obj = co_obj_find (net, index);
394394
if (obj == NULL)
395-
continue;
395+
goto skip;
396396

397397
entry = co_entry_find (net, obj, subindex);
398-
if (entry == NULL || !(entry->flags & OD_WRITE))
399-
continue;
398+
if (entry == NULL || !(entry->flags & OD_WRITE) || (entry->flags & OD_TRANSIENT))
399+
goto skip; /* Not storable in this OD */
400400

401401
if (size <= sizeof (value))
402402
{
@@ -418,16 +418,20 @@ uint32_t co_od_load (co_net_t * net, co_store_t store)
418418
else
419419
{
420420
/* 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-
}
421+
goto skip;
422+
}
427423

428-
if (net->read (arg, &value, size) < 0)
424+
continue;
425+
skip:
426+
while (size > sizeof (value))
427+
{
428+
if (net->read (arg, &value, sizeof (value)) < 0)
429429
goto error;
430+
size -= sizeof (value);
430431
}
432+
433+
if (net->read (arg, &value, size) < 0)
434+
goto error;
431435
}
432436

433437
/* Ignore any error on close */

0 commit comments

Comments
 (0)