[Asterisk-code-review] cli: Fix CLI blocking forever on terminating backslash (asterisk[18])
Friendly Automation
asteriskteam at digium.com
Thu Jun 30 17:33:34 CDT 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18708 )
Change subject: cli: Fix CLI blocking forever on terminating backslash
......................................................................
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
---
M main/asterisk.c
1 file changed, 17 insertions(+), 0 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Benjamin Keith Ford: Looks good to me, but someone else must approve
Friendly Automation: Approved for Submit
diff --git a/main/asterisk.c b/main/asterisk.c
index 9d1561e..0d6217b 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3007,6 +3007,23 @@
/* Only read 1024 bytes at a time */
res = read(ast_consock, mbuf + mlen, 1024);
if (res > 0) {
+ if (!strncmp(mbuf, "Usage:", 6)) {
+ /*
+ * Abort on malformed tab completes
+ * If help (tab complete) follows certain
+ * special characters, the main Asterisk process
+ * provides usage for the internal tab complete
+ * helper command that the remote console processes
+ * use.
+ * If this happens, the AST_CLI_COMPLETE_EOF sentinel
+ * value never gets sent. As a result, we'll just block
+ * forever if we don't handle this case.
+ * If we get command usage on a tab complete, then
+ * we know this scenario just happened and we should
+ * just silently ignore and do nothing.
+ */
+ break;
+ }
mlen += res;
mbuf[mlen] = '\0';
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18708
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670
Gerrit-Change-Number: 18708
Gerrit-PatchSet: 2
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220630/bb1a317a/attachment-0001.html>
More information about the asterisk-code-review
mailing list