添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
贪玩的紫菜  ·  Identifying Long ...·  3 月前    · 
眼睛小的木耳  ·  cURL, Python ...·  5 月前    · 
仗义的斑马  ·  MUZIK AIR·  6 月前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a file created with afl that when opened with libpcap triggers a segfault. My code looks something like:

	pcap = pcap_open_offline(pcap_filename, errbuf);
	pcap_loop(pcap, 0, (pcap_handler)glb_pcap_handler, (u_char *)conf);

I have attempted using pcap_fopen_offline and pcap_file which result in seemingly the same segfault.

pcap_open_offline:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  pcap_loop (p=0x0, cnt=0, callback=0x56229664f2f0 <glb_pcap_handler>, user=0x7fff7c3f2550 "\001") at ./pcap.c:848
848	./pcap.c: No such file or directory.

pcap_file:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  pcap_file (p=0x0) at ./pcap.c:1353
1353	./pcap.c: No such file or directory.

I assume this means that p->rfile is a bad value. Is it possible to detect this bad file before it gets to the point to where things fail?

System details:

root@jessie:/vagrant# tcpdump --version
tcpdump version 4.9.2
libpcap version 1.6.2
OpenSSL 1.0.1t  3 May 2016
root@jessie:/vagrant# uname -a
Linux jessie 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2+deb8u2 (2017-06-26) x86_64 GNU/Linux
root@jessie:/vagrant# cat /etc/issue
Debian GNU/Linux 8 \n \l

I checked the fp like in the case of pcap_fopen_offline

For pcap_fopen_offline(), you have a FILE * that you hand to it, and you've presumably checked whether it's null after assigning the result of fopen() to it (if not, you should, as there's no guarantee that a file open will succeed).

For pcap_open_offline(), you hand it a file name, and it does the fopen() for you and returns a null pointer if the open() fails. If NULL is returned, there is no FILE *, as a null pointer doesn't point to anything - in particular, it doesn't point to a pcap_t that has an rfile member, so p->rfile doesn't exist - there is no *p that contains an rfile member.