Skip to content

Leave room for the terminating NUL in rotctld replies - #440

Open
Wahaj18 wants to merge 1 commit into
csete:masterfrom
Wahaj18:fix-435-rotctld-recv-overflow
Open

Wahaj18 wants to merge 1 commit into
csete:masterfrom
Wahaj18:fix-435-rotctld-recv-overflow

Conversation

@Wahaj18

@Wahaj18 Wahaj18 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

rotctld_socket_rw() passed the full buffer size to recv() and then wrote the terminating NUL at buffout[size]. All three callers (get_pos(), set_pos(), rot_locked_cb()) use 128-byte buffers, so a reply of 128 bytes or more wrote one byte past the end of the stack array.

This reads at most sizeout - 1 bytes, the same as the rigctld helper in gtk-rig-ctrl.c. Normal rotctld replies are far shorter than that, so nothing changes for them.

Tested with an AddressSanitizer harness that runs the function against a socketpair peer: on master, 128- and 200-byte replies trigger a stack-buffer-overflow; with the fix, all reply sizes (20, 127, 128, 200) are handled cleanly. Full build and make check pass with no new warnings.

Fixes #435

rotctld_socket_rw() let recv() fill the whole buffer and then wrote
the terminating NUL at buffout[size], one byte past the end of the
128-byte buffers used by get_pos(), set_pos() and rot_locked_cb()
when the reply was 128 bytes or longer. Read at most sizeout - 1
bytes, as the rigctld helper in gtk-rig-ctrl.c already does.

Fixes csete#435
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.

One-byte stack overflow in gpredict rotctld client (arm64 stack protector abort)

1 participant