Projet

Général

Profil

Tâche #37422

Mis à jour par Gilles Grandgérard il y a 6 mois


Notre code python crée un Bufferoverflow dans common.py

Un bug équivalent est connu : https://github.com/python/cpython/issues/132915

Ce code fonctionne:

<pre>
def get_current_column():
"""Get current terminal column number.

:return: number of columns
:rtype: `list`
:raises: if cannot detect columns number: IOError(25,
'Inappropriate ioctl for device')

"""
w = -1
try:
from fcntl import ioctl
try:
from termios import TIOCGWINSZ
except ImportError:
from TERMIOS import TIOCGWINSZ
tty = sys.stdin.isatty() and sys.stdin or sys.stdout.isatty() and sys.stdout or sys.stderr.isatty() and sys.stderr or None
if tty:
h, w, _, _ = struct.unpack('hhhh', ioctl(tty.fileno(), TIOCGWINSZ, '\0' * struct.calcsize('hhhh')))
except ImportError:
pass
if w > 0:
return w
c = os.environ.get('COLUMNS', 80)
try:
return int(c)
except ValueError:
return 80

#try:
# tty = sys.stdin.isatty() and sys.stdin or sys.stdout.isatty() and sys.stdout or sys.stderr.isatty() and sys.stderr or None
# if tty:
# no = tty.fileno()
# print(no)
# data = fcntl.ioctl(no,termios.TIOCGWINSZ, u'1234')
# data = fcntl.ioctl(no,termios.TIOCGWINSZ, u'1234')
# print(data)
# return struct.unpack('hh', data)[1]
#except (IOError, ValueError,ImportError):
# return 80


</pre>

Retour