Bug 24116

Summary: libpcap error state not reset in pcap_compile_nopcap()
Product: Base System Reporter: Archie Cobbs <archie>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-RELEASE   
Hardware: Any   
OS: Any   

Description Archie Cobbs 2001-01-06 21:30:01 UTC
	When pcap_compile_nopcap() returns an error, subsequent
	compilations of valid input also (incorrectly) return
	an error.

	As a side note, there's no way to get the error string
	when pcap_compile_nopcap() is used because pcap_geterr()
	requires a pcap_t * which you don't have if you're using
	pcap_compile_nopcap(). So a feature request is that
	pcap_geterr() accept NULL as an argument and if so return
	the error from the most recent call to pcap_compile_nopcap().

Fix: 

I'm going to work on this one myself but wanted to
	record it as a PR anyway.
How-To-Repeat: 
	Run this program:

	#include <stdio.h>
	#include <stdlib.h>
	#include <err.h>
	#include <pcap.h>

	#include <net/ethernet.h>

	static char *tests[] = {
		"pcaptest",
		"tcp dst port 80",
		"udp dst host 1.1.1.1 and tcp port 80",
		"tcp dst port 80",
	};

	int
	main(int ac, char **av)
	{
		struct bpf_program bpf;
		int i, r;

		if (ac < 2) {
			ac = sizeof(tests) / sizeof(*tests);
			av = tests;
		}

		memset(&bpf, 0, sizeof(bpf));
		for (i = 1; i < ac; i++) {
			printf("Compiling \"%s\"\n", av[i]);
			r = pcap_compile_nopcap(ETHER_MAX_LEN - ETHER_HDR_LEN,
			    DLT_RAW, &bpf, av[i], 1, ~0);
			if (r != 0)
				printf("--> Failed\n");
			else
				printf("--> OK\n");
		}

		return (0);
	}

	The third compilation should succeed, but it fails.
Comment 1 Archie Cobbs 2001-01-07 00:25:27 UTC
Here is the fix.

-Archie

__________________________________________________________________________
Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com

Index: scanner.l
===================================================================
RCS file: /home/ncvs/src/contrib/libpcap/scanner.l,v
retrieving revision 1.5
diff -u -r1.5 scanner.l
--- scanner.l   2000/01/30 00:43:35     1.5
+++ scanner.l   2001/01/07 00:23:42
@@ -273,6 +273,7 @@
        char *buf;
 {
        in_buffer = buf;
+       yyrestart(NULL);
 }
 
 /*
Comment 2 Archie Cobbs freebsd_committer freebsd_triage 2001-01-10 17:43:57 UTC
State Changed
From-To: open->closed

Patch applied in revisions 1.6 (HEAD) and 1.5.2.1 (RELENG_4).