From archie@packetdesign.com  Sat Jan  6 13:24:03 2001
Return-Path: <archie@packetdesign.com>
Received: from mailman.packetdesign.com (dns.PACKETDESIGN.NET [216.15.46.10])
	by hub.freebsd.org (Postfix) with ESMTP id CCF1037B400
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  6 Jan 2001 13:24:02 -0800 (PST)
Received: from bubba.packetdesign.com (bubba.packetdesign.com [192.168.0.223])
	by mailman.packetdesign.com (8.11.0/8.11.0) with ESMTP id f06LO1Q12938
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 6 Jan 2001 13:24:01 -0800 (PST)
	(envelope-from archie@packetdesign.com)
Received: (from archie@localhost)
	by bubba.packetdesign.com (8.11.1/8.11.1) id f06LO2P12872;
	Sat, 6 Jan 2001 13:24:02 -0800 (PST)
	(envelope-from archie)
Message-Id: <200101062124.f06LO2P12872@bubba.packetdesign.com>
Date: Sat, 6 Jan 2001 13:24:02 -0800 (PST)
From: Archie Cobbs <archie@packetdesign.com>
Reply-To: archie@packetdesign.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: libpcap error state not reset in pcap_compile_nopcap()
X-Send-Pr-Version: 3.2

>Number:         24116
>Category:       bin
>Synopsis:       libpcap error state not reset in pcap_compile_nopcap()
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 06 13:30:01 PST 2001
>Closed-Date:    Wed Jan 10 09:43:57 PST 2001
>Last-Modified:  Wed Jan 10 09:44:33 PST 2001
>Originator:     Archie Cobbs
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
Packet Design, Inc.
>Environment:

	FreeBSD -current and 4.2-REL

>Description:

	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().

>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.

>Fix:

	I'm going to work on this one myself but wanted to
	record it as a PR anyway.


>Release-Note:
>Audit-Trail:

From: Archie Cobbs <archie@packetdesign.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/24116: libpcap error state not reset in pcap_compile_nopcap()
Date: Sat, 06 Jan 2001 16:25:27 -0800

 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);
  }
  
  /*
 
State-Changed-From-To: open->closed 
State-Changed-By: archie 
State-Changed-When: Wed Jan 10 09:43:57 PST 2001 
State-Changed-Why:  
Patch applied in revisions 1.6 (HEAD) and 1.5.2.1 (RELENG_4). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=24116 
>Unformatted:
