Skip to content

fix: cast char to unsigned char in get_uint16 to prevent sign-extension#4035

Open
is-primary-dev wants to merge 1 commit into
LinuxCNC:masterfrom
is-primary-dev:fix-rtapi-get-uint16-sign-extension
Open

fix: cast char to unsigned char in get_uint16 to prevent sign-extension#4035
is-primary-dev wants to merge 1 commit into
LinuxCNC:masterfrom
is-primary-dev:fix-rtapi-get-uint16-sign-extension

Conversation

@is-primary-dev
Copy link
Copy Markdown
Contributor

get_uint16() in uspace_rtapi_main.cc casts char directly to uint16_t. On x86-64 GCC where char is signed, any byte >= 0x80 sign-extends (e.g. 0xA3 becomes 0xFFA3), corrupting the deserialized argument length.

This breaks loadrt for any module argument longer than 127 bytes — the master gets garbage in recv_args and the slave sees "recv_result failed, recv only 0 of 4 bytes".

Fix: cast through unsigned char before widening. The companion push_uint16 already masks with 0xff, so only the read side was affected.

std::vector<char> uses signed char on x86-64 GCC. When a byte >= 0x80
is cast directly to uint16_t, it sign-extends (e.g. 0xA3 becomes
0xFFA3), corrupting the deserialized argument length in the rtapi_app
socket protocol. This causes "arg size not in buffer range" errors for
any loadrt argument longer than 127 bytes.

Cast through unsigned char before widening to uint16_t. The companion
push_uint16 already masks with 0xff, so only the read side was affected.
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.

1 participant