ports/76120: [perl] coredump in perl 5.8.5 in malloc()-call from Perl_pp_split()

Jonas Nagel fireball at zerouptime.ch
Thu Jan 13 12:26:34 UTC 2005


On Thu, 13 Jan 2005 10:57:22 +0100
Anton Berezin <tobez at tobez.org> wrote:
> Jonas, could you maybe re-post a complete minimal script that
> reproduces the problem?  Otherwise it is a bit cryptic.

Of course; actually I thought this question would come but didn't want
to completely clutter up the bug report in first place.

Here a complete script; I also noticed, that the problem apppears only
while I am using the Pcap-Filter function. If I comment setArpFilt()
from the code, then it doesn't crash anymore.

It appears that the Pcap filter function prepares the packet contents in
a way that leads to a crash within the PERL split() function. If there
is also a problem in the Pcap code, is another question. I can't see the
reason from debug output.

 #!/usr/local/bin/perl -w

use strict;
use Net::Pcap;

my $err = "";
my $mynet = "";
my $mymask = "";
my $dev = "";

my $pcap_t = "";
my $snaplen = 1024;
my $promisc = 1;
my $to_ms = 100;

my $cnt = -1;
my $inst = 1;

if(!$ARGV[0]) {
	die("Specify at least one argument!\n");
}

$dev = $ARGV[0];
if(Net::Pcap::lookupnet($dev, \$mynet, \$mymask, \$err)) {
	die("$err\n");
}

print("Network is: ". inet_ntoa($mynet) .", Mask is ".
inet_ntoa($mymask) ."\n");

$pcap_t = Net::Pcap::open_live($dev, $snaplen, $promisc, $to_ms, \$err);
if(!$pcap_t) {
	die("$err\n");
}

# &setArpFilt($pcap_t, $mymask);

Net::Pcap::loop($pcap_t, $cnt, \&display_pkt, $inst);

Net::Pcap::close($pcap_t);

exit;

sub inet_ntoa {
	return join ".",unpack("CCCC",pack("N",shift));
}

sub inet_atoh {
	return split(//,unpack("H*",pack("CCCC",split(/\./,shift))));
}

sub pkt_btoh {
	my @pkt = ();

	my $tmp = unpack("H*",shift);
	my @tmp = split(//,$tmp);
	
	my $rng = (scalar(@tmp)/2);
	for (my $i = 0; $i < $rng; $i++) { 
		$pkt[$i] = shift(@tmp) . shift(@tmp);
	}
	
	return @pkt;
}

sub display_pkt {
	my($inst, $hdr, $pkt) = @_;
	
	my @pkt = &pkt_btoh($pkt);
	if (isArpBC(@pkt)) {
			print("I$inst: $hdr->{'len'} $hdr->{'caplen'} $hdr->{'tv_usec'} - ". join("", at pkt) ."\n");	
	}
}

sub setArpFilt {
	my $pcap_t = shift;
	my $netmask = shift;
	my $optimize = 1;
	my $filter_t = "";
	my $filter_str = "arp";
	
	if(Net::Pcap::compile($pcap_t, \$filter_t, $filter_str, $optimize, $netmask)) {
		die("Net::Pcap::compile returned error: ". Net::Pcap::geterr($pcap_t). "\n");
	}
	if(Net::Pcap::setfilter($pcap_t, $filter_t)) {
		die("Net::Pcap::setfilter returned error: ". Net::Pcap::geterr($pcap_t). "\n");	}
	
	return;
}

-- 
 Jonas Nagel <fireball at zerouptime.ch>



More information about the freebsd-ports-bugs mailing list