Skip to content

server: keep argv copy NULL-terminated in calc_command_start - #1576

Open
arnaldo-delisio wants to merge 1 commit into
tsl0922:mainfrom
arnaldo-delisio:fix/argv-copy-overflow
Open

arnaldo-delisio wants to merge 1 commit into
tsl0922:mainfrom
arnaldo-delisio:fix/argv-copy-overflow

Conversation

@arnaldo-delisio

Copy link
Copy Markdown

Fixes #1575.

calc_command_start() copied argv into argc slots with no NULL terminator. When the command ends in something that looks like a ttyd option taking a value (bash -i), musl's getopt_long sets optind to argc + 1 and permutes up to argv[argc], writing past the buffer. The static release binaries then crash at free(argv_copy).

The copy now has argc + 1 slots with argv_copy[argc] = NULL, like a real argv. The cleanup loop frees up to index argc, because the permutation can move one of the strdup'd strings into that slot.

Not built or run here: I have no musl toolchain available. The crash itself is reproduced with the 1.7.7 release binary, see the issue.

The copy had room for argc pointers and no terminator. When the command
ends in an option-like word that takes a value (bash -i), musl's getopt
sets optind to argc + 1 and permutes up to argv[argc], writing past the
buffer, and the static binaries crash at free(argv_copy).

This branch has not been deployed

No deployments
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.

Static binary crashes at startup when the command ends in an option-like argument (bash -i)

1 participant