Skip to content

vcgencmd: Fix gencmd buffer length and result copy - #229

Merged
pelwell merged 2 commits into
raspberrypi:masterfrom
popcornmix:vcgencmd_buflen
Nov 11, 2026
Merged

pelwell merged 2 commits into
raspberrypi:masterfrom
popcornmix:vcgencmd_buflen

Conversation

@popcornmix

Copy link
Copy Markdown
Contributor

Two small fixes to gencmd():

  • buffer_len for GET_GENCMD_RESULT didn't include the 4-byte response
    word, so the firmware would look for the next tag inside the
    uninitialised command area rather than at the end tag.
  • strncat was given the full size of the result buffer, so a reply
    filling it would write the terminator one byte past the end.

Tested on Pi 4 and Pi 5: output and exit codes match the unpatched
vcgencmd for version, get_config, commands, get_throttled and an
unknown command.

The GET_GENCMD_RESULT value buffer is the response word followed by
MAX_STRING bytes for the command and result, but buffer_len was set to
MAX_STRING. The firmware would then look for the next tag in the last
word of the command area, which is uninitialised.

Set buffer_len to MAX_STRING + 4.
strncat appends up to n characters and then a terminating zero, so
passing the full size of the result buffer could write one byte past
its end when the firmware's reply fills it.

Pass result_len - 1.
@pelwell
pelwell merged commit 3c3d651 into raspberrypi:master Nov 11, 2026
4 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