Author: Matti Picus <[email protected]>
Branch:
Changeset: r94220:03739fa3fc5c
Date: 2018-04-03 06:06 +0300
http://bitbucket.org/pypy/pypy/changeset/03739fa3fc5c/
Log: merge branch which fixes issue #2776
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -91,3 +91,9 @@
.. branch: pyparser-improvements
Improve speed of Python parser, improve ParseError messages slightly.
+
+.. branch: ioctl-arg-size
+
+Work around possible bugs in upstream ioctl users, like CPython allocate at
+least 1024 bytes for the arg in calls to ``ioctl(fd, request, arg)``. Fixes
+issue #2776
diff --git a/pypy/module/fcntl/interp_fcntl.py
b/pypy/module/fcntl/interp_fcntl.py
--- a/pypy/module/fcntl/interp_fcntl.py
+++ b/pypy/module/fcntl/interp_fcntl.py
@@ -204,6 +204,7 @@
# XXX this function's interface is a mess.
# We try to emulate the behavior of Python >= 2.5 w.r.t. mutate_flag
+ IOCTL_BUFSZ = 1024 # like cpython
fd = space.c_filedescriptor_w(w_fd)
op = rffi.cast(rffi.INT, op) # C long => C int
@@ -216,15 +217,19 @@
else:
arg = rwbuffer.as_str()
ll_arg = rffi.str2charp(arg)
+ to_alloc = max(IOCTL_BUFSZ, len(arg))
try:
- rv = ioctl_str(fd, op, ll_arg)
- if rv < 0:
- raise _get_error(space, "ioctl")
- arg = rffi.charpsize2str(ll_arg, len(arg))
- if mutate_flag != 0:
- rwbuffer.setslice(0, arg)
- return space.newint(rv)
- return space.newbytes(arg)
+ with rffi.scoped_alloc_buffer(to_alloc) as buf:
+ rffi.c_memcpy(rffi.cast(rffi.VOIDP, buf.raw),
+ rffi.cast(rffi.VOIDP, ll_arg), len(arg))
+ rv = ioctl_str(fd, op, buf.raw)
+ if rv < 0:
+ raise _get_error(space, "ioctl")
+ arg = rffi.charpsize2str(buf.raw, len(arg))
+ if mutate_flag != 0:
+ rwbuffer.setslice(0, arg)
+ return space.newint(rv)
+ return space.newbytes(arg)
finally:
lltype.free(ll_arg, flavor='raw')
@@ -240,11 +245,15 @@
raise
else:
ll_arg = rffi.str2charp(arg)
+ to_alloc = max(IOCTL_BUFSZ, len(arg))
try:
- rv = ioctl_str(fd, op, ll_arg)
- if rv < 0:
- raise _get_error(space, "ioctl")
- arg = rffi.charpsize2str(ll_arg, len(arg))
+ with rffi.scoped_alloc_buffer(to_alloc) as buf:
+ rffi.c_memcpy(rffi.cast(rffi.VOIDP, buf.raw),
+ rffi.cast(rffi.VOIDP, ll_arg), len(arg))
+ rv = ioctl_str(fd, op, buf.raw)
+ if rv < 0:
+ raise _get_error(space, "ioctl")
+ arg = rffi.charpsize2str(buf.raw, len(arg))
return space.newbytes(arg)
finally:
lltype.free(ll_arg, flavor='raw')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit