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

Kevin Harwell asteriskteam at digium.com
Fri Feb 25 17:08:32 CST 2022


Attention is currently required from: N A.
Kevin Harwell has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/18004 )

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


Patch Set 1: Code-Review-1

(3 comments)

Patchset:

PS1: 
> Not really sure, other than it only affects remote consoles because that's how the buggy logic was o […]
I was curious too so did some testing. As you say the bug would have to occur in an "if ast_opt_remote" block. Within the cli complete code there exists such a block so I surmised it might be happening there. See another comment, but it appears to be hanging on the read function within that block.


File main/asterisk.c:

https://gerrit.asterisk.org/c/asterisk/+/18004/comment/cd68851f_aed92f18 
PS1, Line 2929: 	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';
              : 		}
              : 	}
I'm not entirely sure this is the correct fix for this. At the very least it'll require checking for more values as it also did the same thing for a quote. Each keyboard value should be tested to make sure they don't exhibit the same behavior.


https://gerrit.asterisk.org/c/asterisk/+/18004/comment/d713eb0c_f6990c9e 
PS1, Line 2988: 			res = read(ast_consock, mbuf + mlen, 1024);
After a bit of testing here is where the code hangs. The problem is not that the code is stuck in an infinite loop per se, but that "read" does not ever return.

As to why it does not return when certain values are specified I am unsure. I think that needs to be figured first though as it may lead to a different, and perhaps more appropriate solution.



-- 
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-Reviewer: Friendly Automation
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Attention: N A <mail at interlinked.x10host.com>
Gerrit-Comment-Date: Fri, 25 Feb 2022 23:08:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: N A <mail at interlinked.x10host.com>
Comment-In-Reply-To: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220225/5e33a31f/attachment.html>


More information about the asterisk-code-review mailing list