Merged revisions 84589 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84589 | antoine.pitrou | 2010-09-07 18:30:09 +0200 (mar., 07 sept. 2010) | 5 lines

  Issue #9758: When fcntl.ioctl() was called with mutable_flag set to True,
  and the passed buffer was exactly 1024 bytes long, the buffer wouldn't
  be updated back after the system call.  Original patch by Brian Brazil.
........
This commit is contained in:
Antoine Pitrou 2010-09-07 16:34:47 +00:00
parent 857298100b
commit f4f6171bc0
3 changed files with 31 additions and 6 deletions

View file

@ -1,3 +1,4 @@
import array
import unittest import unittest
from test.test_support import run_unittest, import_module, get_attribute from test.test_support import run_unittest, import_module, get_attribute
import os, struct import os, struct
@ -34,16 +35,36 @@ class IoctlTests(unittest.TestCase):
rpgrp = struct.unpack("i", r)[0] rpgrp = struct.unpack("i", r)[0]
self.assertIn(rpgrp, ids) self.assertIn(rpgrp, ids)
def test_ioctl_mutate(self): def _check_ioctl_mutate_len(self, nbytes=None):
import array buf = array.array('i')
buf = array.array('i', [0]) intsize = buf.itemsize
ids = (os.getpgrp(), os.getsid(0)) ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r") # A fill value unlikely to be in `ids`
fill = -12345
if nbytes is not None:
# Extend the buffer so that it is exactly `nbytes` bytes long
buf.extend([fill] * (nbytes // intsize))
self.assertEqual(len(buf) * intsize, nbytes) # sanity check
else:
buf.append(fill)
with open("/dev/tty", "r") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0] rpgrp = buf[0]
self.assertEquals(r, 0) self.assertEquals(r, 0)
self.assertIn(rpgrp, ids) self.assertIn(rpgrp, ids)
def test_ioctl_mutate(self):
self._check_ioctl_mutate_len()
def test_ioctl_mutate_1024(self):
# Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be
# copied back after the system call.
self._check_ioctl_mutate_len(1024)
def test_ioctl_mutate_2048(self):
# Test with a larger buffer, just for the record.
self._check_ioctl_mutate_len(2048)
def test_ioctl_signed_unsigned_code_param(self): def test_ioctl_signed_unsigned_code_param(self):
if not pty: if not pty:
raise unittest.SkipTest('pty module required') raise unittest.SkipTest('pty module required')

View file

@ -36,6 +36,10 @@ Core and Builtins
Library Library
------- -------
- Issue #9758: When fcntl.ioctl() was called with mutable_flag set to True,
and the passed buffer was exactly 1024 bytes long, the buffer wouldn't
be updated back after the system call. Original patch by Brian Brazil.
- Issue #1100562: Fix deep-copying of objects derived from the list and - Issue #1100562: Fix deep-copying of objects derived from the list and
dict types. Patch by Michele Orrù and Björn Lindqvist. dict types. Patch by Michele Orrù and Björn Lindqvist.

View file

@ -153,7 +153,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
else { else {
ret = ioctl(fd, code, arg); ret = ioctl(fd, code, arg);
} }
if (mutate_arg && (len < IOCTL_BUFSZ)) { if (mutate_arg && (len <= IOCTL_BUFSZ)) {
memcpy(str, buf, len); memcpy(str, buf, len);
} }
if (ret < 0) { if (ret < 0) {