Author sping
Recipients sping
Date 2015-05-22.14:58:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432306683.9.0.470835567306.issue24266@psf.upfronthosting.co.za>
In-reply-to
Content
Hi!


A college of mine ran into a bug with raw_input.
We have a shell derived from stdlib module "cmd" here but the bug shows
with plain raw_input, as well (see demo code).

For the symptoms: the shell is executing commands from history that the
user explicitly chose not to run.  Since our shell does things like
deallocation of LVM volumes, that behavior is rather troublesome :)

How does it happen?

 * When pressing Ctrl+R, an incremental reverse history search is started.
   During that search, you normalled press Escape/Ctrl+J/Ctrl+G to end
   search or Return to pick a result.

 * When you press Ctrl+C though, the next call to the raw_input function
   believes to be in search mode still (while not showing "(reverse-i-search)"
   or indicating search some way).

 * Now when (entering some text and) pressing return now, the string last
   shown during incremental search is being return from raw_input
   (and executed in context of the cmd module).

I have re-produced the issue with Python 2.7.3, 2.7.9, 3.2.3, 3.4.2.

For a workaround, one can handle KeyboardInterrupt and internal adjust
variable rl_readline_state of the C readline library.
I'm attaching (a minimal bug demo and) the ctypes based workaround that
works well over here.
(The workaround demo also shows that readline state is not fully reset
when Ctrl+C was pressed outside of search mode, since flag RL_STATE_DONE
is not set after.)

It would rock the house if this could be fixed in Python.

I'm looking forward to your reply.

Best,



Sebastian
History
Date User Action Args
2015-05-22 14:58:03spingsetrecipients: + sping
2015-05-22 14:58:03spingsetmessageid: <1432306683.9.0.470835567306.issue24266@psf.upfronthosting.co.za>
2015-05-22 14:58:03spinglinkissue24266 messages
2015-05-22 14:58:03spingcreate