Skip to content

Fix PacLed64 null-deref on a controller with an unset Id - #59

Merged
jsm174 merged 1 commit into
vpinball:masterfrom
dynajoe:fix/pacled64-null-deref
Jul 6, 2026
Merged

Fix PacLed64 null-deref on a controller with an unset Id#59
jsm174 merged 1 commit into
vpinball:masterfrom
dynajoe:fix/pacled64-null-deref

Conversation

@dynajoe

@dynajoe dynajoe commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Fix

OnOutputValueChanged used std::map::operator[] on the lazily-populated units map — which inserts a null unit for a missing key and then dereferences it. Its three siblings (Init / Finish / Update) all guard with find(). Guard OnOutputValueChanged the same way.

Why it matters

A PacLed64 configured without an Id leaves m_id = -1; Init's map-populate is skipped for -1, so the first output change hits s_pacLed64Units[-1] → inserts nullptrnull-deref crash. C# pre-populates the dictionary in a static constructor and its indexer throws KeyNotFoundException there instead of crashing.

Found by diffing against the DirectOutput C# source.

OnOutputValueChanged used std::map::operator[] on the lazily-populated units map, which inserts a null unit for a missing key and dereferences it; its three siblings (Init/Finish/Update) all guard with find(). A PacLed64 configured without an Id leaves m_id=-1 (Init map-populate skipped for -1), so the first output change null-derefs. C# throws KeyNotFoundException there. Guard with find() like the siblings.
@jsm174

jsm174 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Hello. Thanks for the PR!

Converting this to draft as per the contributing rules. (I was behind in getting them added as was just done in Visual Pinball).

It's going to take time to review these. libdof is currently is use by several users with a variety of devices, and we have yet to receive issues about this.

Also this definitely needs thorough testing with the actual hardware.

@jsm174
jsm174 marked this pull request as draft July 5, 2026 18:06
@jsm174
jsm174 marked this pull request as ready for review July 6, 2026 19:08
@jsm174
jsm174 merged commit f2097e1 into vpinball:master Jul 6, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants