General Catchall For Bad Commands #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Like some of the other posters on here, I too was hit by the Ctr+C bug. @danielbolan, thanks for fixing the issue! I'll definitely be applying that patch to my app.
Before I saw the fix though, I attempted a resolution myself; my strategy was to generically handle all unsupported commands. Unfortunately, I am about three days old in Node, and I don't understand a whole lot about the telnet protocol, so I couldn't seem to get a complete fix. However, I suspect that completing the fix will be an easy one-liner for someone familiar with the Node API and telnet, so I'm posting the code anyway.
Essentially the problem is a missing index in the array of command handlers; I therefore just added a check to see if a handler is registered. If it isn't, it throws an error, which is caught in the socket's 'data' event handler, the one parsing the raw data.
The trouble is handling the error. Just continuing/breaking from the loop doesn't solve it; the server just hangs, and will not accept any new input. I suspect that the reason for this is because the command associated with Ctr+C is remaining in the buffer, and needs to be cleared out before it can move forward. I can't really seem to figure out how to do that...a little embarrasing, actually.
But, hopefully someone with a better knowledge of Node/telnet can finish this; should beef up the security on all fronts (if it can happen with Ctr+C, I'm guessing it can happen with other (invalid?) sequences). I doubt you'll want to approve the pull request until it's complete; perhaps merge it into a non-master branch?
Thanks so much for creating this; it's been a huge help!
~ ModeratelyTallNate