Bug 150176 - [libpcap] [patch] pcap(3): pcap_read_bpf() p->cc can go negative
Summary: [libpcap] [patch] pcap(3): pcap_read_bpf() p->cc can go negative
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: George V. Neville-Neil
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-09-01 09:00 UTC by guy
Modified: 2022-11-22 22:42 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (1.32 KB, patch)
2010-09-01 09:00 UTC, guy
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description guy 2010-09-01 09:00:10 UTC
In pcap_read_bpf(), ep is set based on the return value of read(), but read() from a BPF device doesn't necessarily return a value that's a multiple of the alignment value for BPF_WORDALIGN().  However, whenever we increment bp, we round up the increment value by a value rounded up by BPF_WORDALIGN(), so we could increment bp past ep after processing the last packet in the buffer.

Fix: Patch attached with submission follows:
How-To-Repeat: Run a program that opens a capture device with a timeout of 0, in a loop, calls pcap_dispatch() with a cnt argument of 1, and reports when it returns a value of 0.  The timeout of 0 means that the read() that libpcap does shouldn't return until there's packet data, so a timeout won't cause pcap_dispatch() to return 0.  Do a large amount of network data transfer, to fill up the BPF bucket; notice that, on occasion, the program will report that pcap_dispatch() returns 0.
Comment 1 guy 2010-09-01 09:15:38 UTC
(Note: that's a patch to tcpdump.org's libpcap on the trunk, but it =
looks as if it applies to top-of-tree FreeBSD as well, albeit with an =
offset.)=
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:28 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 3 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:38:58 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>
Comment 4 Xin LI freebsd_committer freebsd_triage 2022-11-22 22:42:07 UTC
Looks like this was fixed in libpcap 1.2.1 import (59f06eaa08f055b60a0ee4e9694cce270b4bb6d8) in 2012, so closing as fixed.