pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 74 forks source link

pcap data overwritten in a loop #39

Closed rgom closed 5 years ago

rgom commented 7 years ago

As seen in the following issue:

https://github.com/limifly/pypcap/issues/26

when you use the code of: "p=pcap.pcap(file);pkts=readpkts();print(pkts)" it incorrectly reuses old address, meaning that the pkts is broken and using the loop to iterate over pcap.pcap() can lead to unexpected behaviour (e.g. if you copy more than one packet, you actually copy the same one).

This fork seems to be the official one - can it somehow pull in that change?

Regards, Robert

hellais commented 7 years ago

Thanks for reporting this.

Could you submit a PR with the patch?

rgom commented 7 years ago

I can try to submit it, but I'm afraid I'm more like a bug observer than fix implementer, so I couldn't assure quality of the fix is good enough.

Regards, Robert

On Wed, Mar 22, 2017 at 1:51 PM, Arturo Filastò notifications@github.com wrote:

Thanks for reporting this.

Could you submit a PR with the patch?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pynetwork/pypcap/issues/39#issuecomment-288388634, or mute the thread https://github.com/notifications/unsubscribe-auth/AH2lB_zMVv0yCp2yGBAZazw5WJcrKZPqks5roRlQgaJpZM4Mgun6 .

rgom commented 7 years ago

I think I can work it out, but it'll take some time to get accustomed to the code.

Regards, Robert

On Sat, Mar 25, 2017 at 3:30 PM, Arturo Filastò notifications@github.com wrote:

Thanks for this!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pynetwork/pypcap/issues/39#issuecomment-289215238, or mute the thread https://github.com/notifications/unsubscribe-auth/AH2lB2APf85sEGnOYCoOEzxH08mRR3-Yks5rpSUSgaJpZM4Mgun6 .

rgom commented 7 years ago

Well, I've tried hard to reproduce the issue with the following snippet:

def test_pcap_overwritten():
    packets_a = [x[1] for x in pcap.pcap(relative_file('test.pcap')) ]
    packets_a_copy = [t for t in packets_a]
    packets_b = [x[1] for x in pcap.pcap(relative_file('arp.pcap')) ]
    packets_b_copy = [t for t in packets_b]

    # two pcaps to check cross-influence (overwriting)
    assert all(packets_a[i][:] == packets_a_copy[i][:] for i in range(len(packets_a)))
    assert all(packets_b[i][:] == packets_b_copy[i][:] for i in range(len(packets_b)))

    # single pcap to check if a single buffer isn't reused
    assert len(set(p[:] for p in packets_a)) > 1
    assert len(set(p[:] for p in packets_b)) > 1

But I couldn't. The test passed regardless of my attempts to use different copying schemes. Hence I assume the following:

  1. Original issue is incorrect, as the buffers' reprs differ at offset (not only base address, as suggested at the report)
  2. My issue had a different root cause, which I haven't properly identified.

So unless I come up with a way to reproduce the problem, I'd close it as invalid (the same with PR).

Regards, Robert

hellais commented 5 years ago

This should be fixed by #80