Skip to content

Readline input loss

ebranca edited this page Jun 8, 2014 · 2 revisions

Classification

  • Affected Components : readline

  • Operating System : Linux

  • Python Versions : 2.6.x, 2.7.x, 3.1.x, 3.2.x, 3.3.x

  • Reproducible : Yes

Source code

[1]

import sys
import readline

sys.stdout.write('test ')
raw_input()

Steps to Produce/Reproduce

To reproduce the problem copy the source code [1] in a file.

Then execute the script using the following command syntax:

$ python -OOBRtt test.py

Typing a character then hitting backspace deletes "test " as well.

Description

Python acts as an interface to the GNU readline C library and in this case passes the request to the library, thi happens by importing the module readline like import readline .

The GNU readline library needs to know the length of the prompt in order to properly display the data. Python does not takes into consideration this aspect hence the unexpected behaviour.

This is not really a bug in the **GNU readline ** as the requirement is not met. If no length is passed the library deletes the object

Can be considered an implementation problem in both sides as this requirement is known but the python interface does not takes it into account when calls are made.

The library should also check for conditions when requirements are not met and implement proper actions.

As this is a functional problem no error is raised even ic cases when input data is lost.

Workaround

A possible workaround would be to pass an object of known length.

If no text can be passed directly to raw_input is possible to send ' '.

Is also suggested to send text in the form of

    input("test> ")

Instead of

    sys.stdout.write("test> ")
    input()

Secure Implementation

WORK IN PROGRESS

References

[Python "readline" GNU interface][03] [03]:https://docs.python.org/2/library/readline.html

[Python Input Output][02] [02]:https://docs.python.org/2/tutorial/inputoutput.html

[Python bug][01] [01]:http://bugs.python.org/issue12833

[GNU readline library][04] [04]:http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html

  • Home
  • [Security Concerns](Security Concerns)
Clone this wiki locally