Fix premature CAN map limit (~20 signals) caused by off-by-one bounds check aliasing send/recv maps#48
Merged
jsphuebner merged 2 commits intomasterfrom Apr 27, 2026
Conversation
Closed
…ubIndex underflow Agent-Logs-Url: https://github.com/jsphuebner/libopeninv/sessions/16913bdb-6be2-4d7d-80c0-c4aa1253fac0 Co-authored-by: jsphuebner <3882041+jsphuebner@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bug limiting CANMap for transmit messages
Fix premature CAN map limit (~20 signals) caused by off-by-one bounds check aliasing send/recv maps
Apr 27, 2026
Contributor
|
Changes to CanMap look correct to me. Lack of tests for CanSdo isn't great. I never felt strong enough to write them. |
Owner
|
Thanks for reviewing, Dave. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users hit
SDO_ERR_INVIDXat subindex 2 (~20 TX signals) well below the documented limits (50 items / 10 messages) becauseGetMapandRemoveused>instead of>=when bounds-checking the message index againstMAX_MESSAGES.Primary bug: send/recv map aliasing (
canmap.cpp)canSendMapandcanRecvMapare adjacent arrays. IndexMAX_MESSAGES(=10) on the send map silently aliasescanRecvMap[0]:GetMap(false, 10, ...)returned recv map data as a valid TX entry — tools enumerating send messages saw a phantom 11th entryRemove(false, 10, 0)deletedcanRecvMap[0]while the caller believed it was removing a TX entryRemove's case-3 path,lastIdxisuint8_tand(0 + 10) < 10is immediately false, solastIdx--underflows to 255 — a massive out-of-bounds write corrupting adjacent memoryThe combination consumes send map slots illegitimately, causing
CAN_ERR_MAXMESSAGESfar below the actual limit.Secondary bugs:
CanSdoinitialization (cansdo.cpp)mapIdinitialized to0instead of0xFFFFFFFF— subindex-1 handler accepted a write without a prior valid subindex-0 (CAN ID)mapInfoleft uninitialized — garbagenumBits != 0could trigger a spuriousAddSend/AddRecvon the first subindex-2 SDO after bootuint8_tunderflow inReadOrDeleteCanMap:MAX(0, sdo->subIndex - 1) / 2wraps to 127 whensubIndex == 0, making all reads/deletes of the CAN-ID sub-object fail with SDO_ABORTTests
Two regression tests added to
test_canmap.cpp:get_map_at_max_messages_returns_null— verifiesGetMap(false, MAX_MESSAGES, ...)returns null, not recv map dataremove_at_max_messages_is_safe— verifiesRemove(false, MAX_MESSAGES, 0)is a no-op and leavescanRecvMap[0]intact