kbandla / libdnet

Automatically exported from code.google.com/p/libdnet
Other
1 stars 0 forks source link

ip_cksum_add bug in dnet.pyx #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

libdnet-1.12 uses a deprecated function prototype of PyObject_AsReadBuffer, 
causing an overflow on 64-bit builds. Calling dnet.ip_cksum_add(buf, x) (with 
non-zero x) will cause ip_cksum_add in ip-util.c to get cksum = 0. 

An example of this bug breaking something can be found in 
dpkt/ip.py::IP:__str__ :
                s = dpkt.in_cksum_add(0, s)
                s = dpkt.in_cksum_add(s, p)

(where dpkt.in_cksum_add is aliased to dnet.ip_cksum_add in dpkt.py)

This bug causes dpkt to insert incorrect checksums for UDP/TCP packets, as the 
first result from ip_cksum_add is essentially ignored.

What is the expected output? What do you see instead?

I expect cksum to be maintained between the python-c call, instead of getting 
overwritten as 0.

What version of the product are you using? On what operating system?

dnet-1.12, ubuntu 10.10.

Please provide any additional information below.

I've provided a patch to libdnet-1.12/python/dnet.pyx that fixes this problem. 
The solution is to use Py_ssize_t instead of int. (this patch also includes 
modifications to allow dnet.pyx to build under the version of pyrexc I pulled 
out of the Ubuntu repository (pyrexc 0.9.8.5))

Original issue reported on code.google.com by nexter...@gmail.com on 31 Dec 2011 at 7:38

Attachments: