<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://reviewboard.asterisk.org/r/1180/">https://reviewboard.asterisk.org/r/1180/</a>
</td>
</tr>
</table>
<br />
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.orgrb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for Asterisk Developers.</div>
<div>By jrose.</div>
<p style="color: grey;"><i>Updated 2011-04-15 09:15:42.223051</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Changes</h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Removed comment about regular expression matching because I do not see anything resembling regular expression matching going on where that comment is located.
Other changes based on Russell's last volley of comments.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">CLI tab completion can be confused by command options if there is some substring matching going on. This has only been the case for commands once so far that I've actually been able to find, and it only existed in 1.6.2.
dahdi show channels has options [trunkgroup|group|context]
This example is tab completing against group. If dahdi show channels group is in cli and the user tabs, the word group will be added again. This can be repeated infinitely until the cli starts spitting argument errors.
When the tab completion is being performed in ast_cli_generator, word_match is invoked using the cli word "group" against the command string [trunkgroup|group|context]. Inside this message, a string pointer pos is set using strcasestr(cli_word, cmd) which sets the cli command to the first occurence of the word in the command string. Unfortunately this message is naive to the occurence of substrings, so the resulting pos for group is:
"group|group|context]"
instead of the expected "group|context]".
An if statement near the end of the word_match function evaluates the string to see if the word is a command word by checking if the character before it is a a cli reserved character (such as {, |, or [)
since the character before pos in this case is 'k', it skips this if clause and returns -1 instead of the expected 1, causing it to match back in the ast_cli_generator function.
My fix for this is to search against the various reserved characters concatenated with the cli word. Once one is found, another search is done on that substring to put it at the actual command so it is looking at the actual word rather than <reserved_character>word. I think there is probably a way to search against all of these characters at once without having to rely on string concatenation, possibly with regular expressions, but I'm not especially certain on that and if anyone has any recommendations on that I'd be glad to follow them.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Obviously a lot of tab completion on various inputs of cli words was used, but I also was using some fairly verbose checks of what was going on in the word_match function to make sure things were happening the way I think they were happening.</pre>
</td>
</tr>
</table>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>
<a href="https://issues.asterisk.org/view.php?id=17494">17494</a>
</div>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> (updated)</h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/branches/1.6.2/main/cli.c <span style="color: grey">(313276)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/1180/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>