This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fcntl.ioctl fails to copy back exactly-1024 buffer
Type: Stage: resolved
Components: Library (Lib) Versions: Python 2.4, Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: G2P, ajaksu2, eichin, nnorwitz
Priority: normal Keywords:

Created on 2006-07-11 21:38 by eichin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
scsiinfo.py eichin, 2006-07-11 21:39 ioctl bug example
Messages (5)
msg29134 - (view) Author: Mark Eichin (eichin) Date: 2006-07-11 21:38
The appended code is a simple call of the SCSI Inquiry
ioctl, based on what scsi-tools scsiinfo.c does.  The
intended behaviour is simple - pass it /dev/sg0 (or any
scsi device, really) and it pulls out the vendor,
product and revision from the returned buffer.

However, if you change PAD_SIZE, the behaviour changes:
at 1023 and 1025, it does what is expected; at 1024,
the second assertion fires, because the array b on
output hasn't changed at all.

Not sure if there's a different ioctl that can
demonstrate this more easily (this needs root and a
scsi device, though it does explicitly open it
readonly) but it points in the direction of a fencepost
error in the "if the supplied buffer is less than 1024
bytes long it is first copied into a static buffer 1024
bytes long which is then passed to ioctl and copied
back into the supplied buffer" behaviour in current
documentation.

observed under:
Python 2.4.1 (#2, May  5 2005, 11:32:06)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
(on debian sarge.)

I didn't see it mentioned among the ioctl bugs in the
sourceforge tracker...
msg29135 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-12 05:33
Logged In: YES 
user_id=33168

This code was recently changed.  It is not in any released
version AFAIK.  Can you try 2.5b2 which recently came out? 
If not, can you try 2.4.3+ from SVN?  This is the version
that will become 2.4.4.  I think the problem may be fixed. 
The patch was for http://python.org/sf/1433877 .
msg84511 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 05:19
Closing due to lack of feedback.
msg172174 - (view) Author: (G2P) Date: 2012-10-06 09:46
The bug still exists in Python 2.6 (2.6.7-4ubuntu2). Python 2.7 (2.7.3-5ubuntu4) works correctly. I don't have Python 2.5 on hand to check.

Here is a very simple test case:

import array, fcntl
buf = array.array('B', [0]*1024)
fcntl.ioctl(0, termios.TIOCGPGRP, buf, 1)
assert any(by != 0 for by in buf)
msg172175 - (view) Author: (G2P) Date: 2012-10-06 09:55
Also happens in 2.5.2-2ubuntu6 and 2.4.5-1ubuntu4.2, FWIW.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43649
2012-10-06 09:55:37G2Psetmessages: + msg172175
versions: + Python 2.6
2012-10-06 09:46:33G2Psetnosy: + G2P
messages: + msg172174
2009-03-30 05:19:05ajaksu2setstatus: open -> closed

nosy: + ajaksu2
messages: + msg84511

resolution: out of date
stage: resolved
2006-07-11 21:38:59eichincreate