[Asterisk-code-review] cli: Fix infinite loop on terminating backslash (asterisk[master])

N A asteriskteam at digium.com
Sat Feb 5 15:20:43 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18004 )


Change subject: cli: Fix infinite loop on terminating backslash
......................................................................

cli: Fix infinite loop 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 stuck in an infinite
loop reading the command completion. CTRL+C
and other key combinations have no impact on
the CLI session.

This changes the remote console behavior to
match foreground console behavior by discarding
trailing backslashes in commands before doing
command completion, since the backslash is not
being used for escaping as they are intended for.

ASTERISK-29822 #close

Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670
---
M main/asterisk.c
1 file changed, 16 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/04/18004/1

diff --git a/main/asterisk.c b/main/asterisk.c
index 4520318..d0ac702 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2925,6 +2925,22 @@
 	savechr = *(char *)lf->cursor;
 	*(char *)lf->cursor = '\0';
 	ptr = (char *)lf->cursor;
+
+	if (ast_opt_remote) {
+		/*
+		* This fixes the bug where if the last char typed in
+		* the CLI before pressing TAB or ? is a backslash,
+		* then we get stuck in an infinite loop on the call
+		* to read in this function. This only affects remote
+		* console, so if we encounter a terminating backslash,
+		* get rid of it for the command completion, so the
+		* behavior is the same as foreground console. */
+		char *c = (char*) lf->buffer + strlen(lf->buffer) - 1;
+		if (*c == '\\') {
+			*c = '\0';
+		}
+	}
+
 	if (ptr) {
 		while (ptr > lf->buffer) {
 			if (isspace(*ptr)) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18004
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670
Gerrit-Change-Number: 18004
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220205/5c0d386e/attachment.html>


More information about the asterisk-code-review mailing list