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.

Author gk
Recipients gk
Date 2010-09-03.16:54:10
SpamBayes Score 1.9621682e-10
Marked as misclassified No
Message-id <1283532852.64.0.959169848478.issue9758@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,

It looks like something is broken in ioctl in 3.2 when the supplied (mutable) bytearray is exactly 1024 bytes long - the result is not copied into the buffer after the ioctl succedes:

def open_tuntap(type, name):
        TUN_TYPE = {
                'TUN' : 0x0001,
                'TAP' : 0x0002
        }

        TUNSETIFF = 0x400454ca

        dev = os.open('/dev/net/tun', os.O_RDWR)
        buf = bytearray(SET_LEN_HERE)
        name = name[:16]
        buf[:len(name)] = name
        buf[16:18] = TUN_TYPE[type].to_bytes(2, sys.byteorder)
        fcntl.ioctl(dev, TUNSETIFF, buf, True)
        print(buf)
        print(len(buf))

open_tuntap('TAP', b'madtun%d')

Now try it with SET_LEN_HERE = 1024, 1023, 1025 and any other values. For < 1024 it copies to the static buffer and back, for > 1024 it operates on the buffer itself (hopefully) and for 1024 it ignores the modified buffer completely. It's probably some corner case bug.

The example was tested under Linux 2.6.35.

Python 3.2a1+ (py3k:84054, Sep  3 2010, 01:45:35) 
[GCC 4.4.2] on linux2
History
Date User Action Args
2010-09-03 16:54:12gksetrecipients: + gk
2010-09-03 16:54:12gksetmessageid: <1283532852.64.0.959169848478.issue9758@psf.upfronthosting.co.za>
2010-09-03 16:54:11gklinkissue9758 messages
2010-09-03 16:54:10gkcreate