Opened 3 years ago

Closed 3 years ago

#5246 defect closed fixed (fixed)

twisted.conch.stdio crashes on some unprintable characters

Reported by: djfroofy Owned by: exarkun
Priority: normal Milestone:
Component: conch Keywords:
Cc: z3p Branch: branches/recvline-fnkeys-5246
(diff, github, buildbot, log)
Author: djfroofy Launchpad Bug:

Description

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/log.py", line 84, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/log.py", line 69, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/python/context.py", 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/context.py", line 81, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
	    why = getattr(selectable, method)()
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/process.py", line 257, in doRead
	    return fdesc.readFromFD(self.fd, self.dataReceived)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/fdesc.py", line 94, in readFromFD
	    callback(output)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/process.py", line 260, in dataReceived
	    self.proc.childDataReceived(self.name, data)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/internet/_posixstdio.py", line 89, in childDataReceived
	    self.protocol.dataReceived(data)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/insults.py", line 445, in dataReceived
	    self._handleControlSequence(''.join(self.escBuf) + ch)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/insults.py", line 465, in _handleControlSequence
	    f(self, self.terminalProtocol, buf[:-1])
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/insults/insults.py", line 564, in tilde
	    handler.keystrokeReceived(map[v], None)
	  File "/home/drew/Envs/snd/local/lib/python2.7/site-packages/twisted/conch/recvline.py", 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 djfroofy 3 years ago.
Fix with unit test

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by DefaultCC Plugin

  • Cc z3p added

Changed 3 years ago by djfroofy

Fix with unit test

comment:2 Changed 3 years ago by djfroofy

  • Keywords review added

comment:3 Changed 3 years ago by exarkun

  • Author set to exarkun
  • Branch set to branches/recvline-fnkeys-5246

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

comment:4 Changed 3 years ago by exarkun

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

refs #5246

comment:5 Changed 3 years ago by exarkun

  • Author changed from exarkun to djfroofy
  • Keywords review removed
  • Owner set to exarkun

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 test_recvline.py, 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 3 years ago by exarkun

  • Resolution set to fixed
  • Status changed from new to closed

(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.