Skip to content

Commit b841845

Browse files
InterLinked1kharwell
authored andcommitted
cli: Fix CLI blocking forever on terminating backslash
A corner case exists in CLI parsing where if a CLI user in a remote console ends with a backslash and then invokes command completion (using TAB or ?), then the console will freeze forever until a SIGQUIT signal is sent to the process, due to getting blocked forever reading the command completion. CTRL+C and other key combinations have no impact on the CLI session. This occurs because, in such cases, the CLI process is waiting for AST_CLI_COMPLETE_EOF to appear in the buffer from the main process, but instead the main process is confused by the funny syntax and thus prints out the CLI help. As a result, the CLI process is stuck on the read call, waiting for the completion that will never come. This prevents blocking forever by checking if the data from the main process starts with "Usage:". If it does, that means that CLI help was sent instead of the tab complete vector, and thus the CLI should bail out and not wait any longer. ASTERISK-29822 #close Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670
1 parent ae8a36a commit b841845

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main/asterisk.c

+17
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,23 @@ static char *cli_complete(EditLine *editline, int ch)
30073007
/* Only read 1024 bytes at a time */
30083008
res = read(ast_consock, mbuf + mlen, 1024);
30093009
if (res > 0) {
3010+
if (!strncmp(mbuf, "Usage:", 6)) {
3011+
/*
3012+
* Abort on malformed tab completes
3013+
* If help (tab complete) follows certain
3014+
* special characters, the main Asterisk process
3015+
* provides usage for the internal tab complete
3016+
* helper command that the remote console processes
3017+
* use.
3018+
* If this happens, the AST_CLI_COMPLETE_EOF sentinel
3019+
* value never gets sent. As a result, we'll just block
3020+
* forever if we don't handle this case.
3021+
* If we get command usage on a tab complete, then
3022+
* we know this scenario just happened and we should
3023+
* just silently ignore and do nothing.
3024+
*/
3025+
break;
3026+
}
30103027
mlen += res;
30113028
mbuf[mlen] = '\0';
30123029
}

0 commit comments

Comments
 (0)