Skip to content

Fix init packets clobbering output buffer - #26

Open
madleech wants to merge 3 commits into
masterfrom
fix-init-clobbering-buffer
Open

Fix init packets clobbering output buffer#26
madleech wants to merge 3 commits into
masterfrom
fix-init-clobbering-buffer

Conversation

@madleech

Copy link
Copy Markdown
Owner

Fix for the issue raised in #25. It now stores init packets in their own buffer, but this buffer is only created if an init handler is set up, so memory usage isn't increased for most users.

Breaking change: process() now no longer returns true for INIT packets.

Also update the documentation to correct the incorrect documentation of the process function; it returns a boolean, not the packet type.

@brocci

brocci commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@madleech Looks OK to me. But I cannot do any testing as I am away from home.

Comment thread src/CMRI.cpp
_init_buffer = (char *)malloc(_init_length);
if (_init_buffer == nullptr)
_init_length = 0; // allocation failed: discard INIT bodies rather than risk a null write
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically this will have issues if ever the host's init message ever changes length after being processed once. The truncation keeps memory problems at bay, but the init handler won't ever see those truncated bytes...
Not a practical issue with JMRI today...

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.

3 participants