<p>Kevin Harwell <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18707">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved; Approved for Submit
  Benjamin Keith Ford: Looks good to me, but someone else must approve

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cli: Fix CLI blocking forever on terminating backslash<br><br>A corner case exists in CLI parsing where if<br>a CLI user in a remote console ends with<br>a backslash and then invokes command completion<br>(using TAB or ?), then the console will freeze<br>forever until a SIGQUIT signal is sent to the<br>process, due to getting blocked forever<br>reading the command completion. CTRL+C<br>and other key combinations have no impact on<br>the CLI session.<br><br>This occurs because, in such cases, the CLI<br>process is waiting for AST_CLI_COMPLETE_EOF<br>to appear in the buffer from the main process,<br>but instead the main process is confused by<br>the funny syntax and thus prints out the CLI help.<br>As a result, the CLI process is stuck on the<br>read call, waiting for the completion that<br>will never come.<br><br>This prevents blocking forever by checking<br>if the data from the main process starts with<br>"Usage:". If it does, that means that CLI help<br>was sent instead of the tab complete vector,<br>and thus the CLI should bail out and not wait<br>any longer.<br><br>ASTERISK-29822 #close<br><br>Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670<br>---<br>M main/asterisk.c<br>1 file changed, 17 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/asterisk.c b/main/asterisk.c</span><br><span>index bc9497f..8a98ea1 100644</span><br><span>--- a/main/asterisk.c</span><br><span>+++ b/main/asterisk.c</span><br><span>@@ -3004,6 +3004,23 @@</span><br><span>                    /* Only read 1024 bytes at a time */</span><br><span>                         res = read(ast_consock, mbuf + mlen, 1024);</span><br><span>                  if (res > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                             if (!strncmp(mbuf, "Usage:", 6)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                  /*</span><br><span style="color: hsl(120, 100%, 40%);">+                                     * Abort on malformed tab completes</span><br><span style="color: hsl(120, 100%, 40%);">+                                    * If help (tab complete) follows certain</span><br><span style="color: hsl(120, 100%, 40%);">+                                      * special characters, the main Asterisk process</span><br><span style="color: hsl(120, 100%, 40%);">+                                       * provides usage for the internal tab complete</span><br><span style="color: hsl(120, 100%, 40%);">+                                        * helper command that the remote console processes</span><br><span style="color: hsl(120, 100%, 40%);">+                                    * use.</span><br><span style="color: hsl(120, 100%, 40%);">+                                        * If this happens, the AST_CLI_COMPLETE_EOF sentinel</span><br><span style="color: hsl(120, 100%, 40%);">+                                  * value never gets sent. As a result, we'll just block</span><br><span style="color: hsl(120, 100%, 40%);">+                                    * forever if we don't handle this case.</span><br><span style="color: hsl(120, 100%, 40%);">+                                   * If we get command usage on a tab complete, then</span><br><span style="color: hsl(120, 100%, 40%);">+                                     * we know this scenario just happened and we should</span><br><span style="color: hsl(120, 100%, 40%);">+                                   * just silently ignore and do nothing.</span><br><span style="color: hsl(120, 100%, 40%);">+                                        */</span><br><span style="color: hsl(120, 100%, 40%);">+                                   break;</span><br><span style="color: hsl(120, 100%, 40%);">+                                }</span><br><span>                            mlen += res;</span><br><span>                                 mbuf[mlen] = '\0';</span><br><span>                   }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18707">change 18707</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18707"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I9810ac59304fec162da701653c9c834f0ec8f670 </div>
<div style="display:none"> Gerrit-Change-Number: 18707 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>