Opened 7 years ago

Closed 7 years ago

#5246 defect closed fixed (fixed)

twisted.conch.stdio crashes on some unprintable characters

Reported by: Drew Smathers Owned by: Jean-Paul Calderone
Priority: normal Milestone:
Component: conch Keywords:
Cc: z3p Branch: branches/recvline-fnkeys-5246
branch-diff, diff-cov, branch-cov, buildbot
Author: djfroofy


This appears to only affect python2.7 and latter version but hitting any function key (F1 etc.), PgUp, PgDn, etc will crash a conch stdio session with the following traceback:

2011-09-01 21:24:41-0400 [-] Unhandled Error
	Traceback (most recent call last):
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/", line 84, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/", line 69, in callWithContext
	    return{ILogContext: newCtx}, func, *args, **kw)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/", line 118, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/", line 81, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/", line 146, in _doReadOrWrite
	    why = getattr(selectable, method)()
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/", line 257, in doRead
	    return fdesc.readFromFD(self.fd, self.dataReceived)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/", line 94, in readFromFD
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/", line 260, in dataReceived
	    self.proc.childDataReceived(, data)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/", line 89, in childDataReceived
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/", line 445, in dataReceived
	    self._handleControlSequence(''.join(self.escBuf) + ch)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/", line 465, in _handleControlSequence
	    f(self, self.terminalProtocol, buf[:-1])
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/", line 564, in tilde
	    handler.keystrokeReceived(map[v], None)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/", line 201, in keystrokeReceived
	    elif keyID in string.printable:
	exceptions.TypeError: 'in <string>' requires string as left operand, not _const
2011-09-01 21:24:42-0400 [-] Main loop terminated.

Attachments (1)

recvline-5246.patch (1.5 KB) - added by Drew Smathers 7 years ago.
Fix with unit test

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by DefaultCC Plugin

Cc: z3p added

Changed 7 years ago by Drew Smathers

Attachment: recvline-5246.patch added

Fix with unit test

comment:2 Changed 7 years ago by Drew Smathers

Keywords: review added

comment:3 Changed 7 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/recvline-fnkeys-5246

(In [32501]) Branching to 'recvline-fnkeys-5246'

comment:4 Changed 7 years ago by Jean-Paul Calderone

(In [32502]) Apply recvline-5246.patch

refs #5246

comment:5 Changed 7 years ago by Jean-Paul Calderone

Author: exarkundjfroofy
Keywords: review removed
Owner: set to Jean-Paul Calderone

Thanks! I was able to reproduce this on Python 2.6 as well (which is nice, because it's not obvious why only Python 2.7 would have this problem).

The fix looks correct. Just a couple minor comments:

  1. Despite the prevailing convention in, new test methods should be named like test_unprintableCharacters and have docstrings. :)
  2. Using a set for _printableChars seems slightly more logical, since ordering isn't relevant here, and it might be a trivial performance improvement as well.

These are minor, so I'll do them and then merge if the build results look alright.

comment:6 Changed 7 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [32505]) Merge recvline-fnkeys-5246

Author: djfroofy Reviewer: exarkun Fixes: #5246

Handle non-string keystrokes in twisted.conch.recvline.RecvLine.keystrokeReceived so that they do not cause a exception to be raised when they are received. This makes things like F1-F12 and PGUP and PGDN not lead to a RecvLine being disconnected.

Note: See TracTickets for help on using tickets.