Skip to content

Don't truncate long commands in r_sys_cmdf and r_sys_cmd_strf ##util - #27303

Merged
trufae merged 1 commit into
radareorg:masterfrom
Thanatos9404:sys-cmdf-no-truncate
Nov 1, 2026
Merged

trufae merged 1 commit into
radareorg:masterfrom
Thanatos9404:sys-cmdf-no-truncate

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor
  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description

Follow-up to #27287. r_sys_cmdf and r_sys_cmd_strf formatted into a char cmd[4096] and ignored what vsnprintf returned, so a longer command line was cut at 4095 bytes and whatever was left still ran. The effect depends on where the cut falls:

  • Inside a quoted argument: sh rejects the whole command, so r_file_copy and r_file_move fail when the two escaped paths add up to more than 4 KiB.
  • Between arguments: sh runs a shorter command, for example one without its trailing > file redirection.

Both now format with r_str_newvf and free the string after running it. They return -1 or NULL if formatting or the allocation fails, where master ran whatever was in the buffer. They do the same for a NULL fmt, as r_core_cmdf does.

On Windows, r_sys_cmd_strf can now pass command lines longer than 32 KiB to r_sys_create_child_proc_w32. #27302 fixes the buffer size there.

Testing

test_sys_cmdf_long in test/unit/test_util.c passes a 5000-byte argument through both: r_sys_cmdf with a redirection after it, and r_sys_cmd_strf capturing the output. I built with ./configure && make on Linux (gcc). On master the test fails at "r_sys_cmdf keeps the redirection after a long argument". With this change it passes, along with the rest of test_util. The other unit tests pass except the nine that need radare2-testbins or radare2 in PATH. sys/lint.py --all and git diff --check are clean.

@trufae
trufae merged commit eb9c882 into radareorg:master Nov 1, 2026
50 checks passed
@trufae

trufae commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Nice scary limit. Thanks for solving it out!

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