Skip to content

Commit cc23e9b

Browse files
JoeMattclaude
andcommitted
Invalidate events with unresolved callbacks on state load
If a saved event references a callback not in the registry (e.g. from a newer version), id_to_callback returns NULL. Previously the event was still marked valid, risking a NULL function pointer call in HandleNextEvent. Now events with NULL callbacks are forced invalid. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 07cdb71 commit cc23e9b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/event.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ size_t EventStateLoad(const uint8_t *buf)
337337
STATE_LOAD_VAR(buf, etype);
338338
STATE_LOAD_VAR(buf, etime);
339339

340-
eventList[i].valid = valid ? true : false;
341340
eventList[i].timerCallback = id_to_callback(cb_id);
341+
/* Invalidate event if callback could not be resolved */
342+
eventList[i].valid = (valid && eventList[i].timerCallback) ? true : false;
342343
eventList[i].eventType = etype;
343344
eventList[i].eventTime = etime;
344345
}
@@ -354,8 +355,9 @@ size_t EventStateLoad(const uint8_t *buf)
354355
STATE_LOAD_VAR(buf, etype);
355356
STATE_LOAD_VAR(buf, etime);
356357

357-
eventListJERRY[i].valid = valid ? true : false;
358358
eventListJERRY[i].timerCallback = id_to_callback(cb_id);
359+
/* Invalidate event if callback could not be resolved */
360+
eventListJERRY[i].valid = (valid && eventListJERRY[i].timerCallback) ? true : false;
359361
eventListJERRY[i].eventType = etype;
360362
eventListJERRY[i].eventTime = etime;
361363
}

0 commit comments

Comments
 (0)