sngrep icon indicating copy to clipboard operation
sngrep copied to clipboard

v1.4.4 on FreeBSD segfault when trying to save pcaps

Open dunst0 opened this issue 9 years ago • 9 comments

With the latest tag I experience segfaults when I try to save the capture.

sngrep - 1.4.4
Copyright (C) 2013-2017 Irontec S.L.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
 * Compiled with OpenSSL support.
 * Compiled with Perl Compatible regular expressions support.
 * Compiled with IPv6 support.
 * Compiled with EEP/HEP support.

Written by Ivan Alonso [aka Kaian]

Sorry no debugging symbols.

(gdb) bt full
#0  0x00000008020b7633 in vfprintf_l () from /lib/libc.so.7
No symbol table info available.
#1  0x0000000802109086 in vsprintf () from /lib/libc.so.7
No symbol table info available.
#2  0x0000000000417d99 in dialog_run ()
No symbol table info available.
#3  0x0000000000425598 in save_to_file ()
No symbol table info available.
#4  0x00000000004250fe in save_handle_key ()
No symbol table info available.
#5  0x0000000000416486 in ui_handle_key ()
No symbol table info available.
#6  0x000000000041725e in ui_wait_for_input ()
No symbol table info available.
#7  0x000000000041042a in main ()
No symbol table info available.

dunst0 avatar Nov 28 '17 10:11 dunst0

Hi @dunst0

Thanks for reporting!

I have tried with the pcap in test folder without problem.

  • Does this problem happen every time you want to save or only sometimes?
  • Are you saving from a pcap file or online capture?
  • Do you have permission to write in destination directory?

The existing dialog_runs in save screen are the following, one of them is causing the crash:

dialog_run("Please enter a valid filename");
dialog_run("Unable to save: No selected dialogs.");
dialog_run(capture_last_error());
dialog_run("Error: %s", strerror(errno));
dialog_run("Successfully saved selected SIP message to %s", savefile);
dialog_run("Successfully saved %d dialogs to %s", vector_iterator_count(&calls), savefile);

Thanks!!

Kaian avatar Nov 28 '17 14:11 Kaian

Hey @Kaian thanks for your quick response, sorry for my late reply.

Does this problem happen every time you want to save or only sometimes?

Yes it does.

Are you saving from a pcap file or online capture?

It happens only with online capture. If I just capture and safe it in a file everything is ok. When a pcap file is opened offline, it possible to save dialogs.

Do you have permission to write in destination directory?

Yes, tried with root and it happening as well.

dunst0 avatar Dec 01 '17 08:12 dunst0

I tried to enable debug, to get a better stack trace but I can't enable debug.

Without debug:

root@host:/usr/local/src/sngrep # env CFLAGS="-I/usr/include -I/usr/local/include" LDFLAGS="-L/usr/lib -L/usr/local/lib" ./configure --enable-ipv6 --enable-eep --with-openssl --with-pcre
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for style of include used by make... GNU
checking for gcc... no
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking whether cc understands -c and -o together... yes
checking dependency style of cc... gcc3
checking how to run the C preprocessor... cc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether we are using the GNU C compiler... (cached) yes
checking whether cc accepts -g... (cached) yes
checking for cc option to accept ISO C89... (cached) none needed
checking whether cc understands -c and -o together... (cached) yes
checking dependency style of cc... (cached) gcc3
checking for g++... no
checking for c++... c++
checking whether we are using the GNU C++ compiler... yes
checking whether c++ accepts -g... yes
checking dependency style of c++... gcc3
checking whether ln -s works... yes
checking for egrep... (cached) /usr/bin/grep -E
checking for pthread_create in -lpthread... yes
checking for pcap_open_offline in -lpcap... yes
checking pcap.h usability... yes
checking pcap.h presence... yes
checking for pcap.h... yes
checking ncurses.h usability... yes
checking ncurses.h presence... yes
checking for ncurses.h... yes
checking for initscr in -lncurses... yes
checking for new_panel in -lpanel... yes
checking for new_form in -lform... yes
checking for new_item in -lmenu... yes
checking for SSL_new in -lssl... yes
checking for EVP_get_cipherbyname in -lcrypto... yes
checking pcre.h usability... yes
checking pcre.h presence... no
configure: WARNING: pcre.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: pcre.h: proceeding with the compiler's result
checking for pcre.h... yes
checking for pcre_exec in -lpcre... yes
checking for netinet/in.h... yes
checking for netinet/ip6.h... yes

 ██╗██████╗  ██████╗ ███╗   ██╗████████╗███████╗ ██████╗
 ██║██╔══██╗██╔═══██╗████╗  ██║╚══██╔══╝██╔════╝██╔════╝
 ██║██████╔╝██║   ██║██╔██╗ ██║   ██║   █████╗  ██║     
 ██║██╔══██╗██║   ██║██║╚██╗██║   ██║   ██╔══╝  ██║     
 ██║██║  ██║╚██████╔╝██║ ╚████║   ██║   ███████╗╚██████╗
 ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝   ╚═╝   ╚══════╝ ╚═════╝

configure: 
configure: sngrep configure finished                            	
configure: ====================================================== 	
configure: GnuTLS Support               : no		
configure: OpenSSL Support              : yes 			
configure: Unicode Support              : no  		
configure: Perl Expressions Support     : yes              
configure: IPv6 Support                 : yes               
configure: EEP Support                  : yes               
configure: ====================================================== 	
configure: 
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config/Makefile
config.status: creating doc/Makefile
config.status: creating tests/Makefile
config.status: creating src/config.h
config.status: src/config.h is unchanged
config.status: executing depfiles commands

With debug:

root@host:/usr/local/src/sngrep # env CFLAGS="-I/usr/include -I/usr/local/include" LDFLAGS="-L/usr/lib -L/usr/local/lib" ./configure --enable-ipv6 --enable-eep --with-openssl --with-pcre --enable-debug
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for style of include used by make... GNU
checking for gcc... no
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking whether cc understands -c and -o together... yes
checking dependency style of cc... gcc3
checking how to run the C preprocessor... cc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether we are using the GNU C compiler... (cached) yes
checking whether cc accepts -g... (cached) yes
checking for cc option to accept ISO C89... (cached) none needed
checking whether cc understands -c and -o together... (cached) yes
checking dependency style of cc... (cached) gcc3
checking for g++... no
checking for c++... c++
checking whether we are using the GNU C++ compiler... no
checking whether c++ accepts -g... yes
checking dependency style of c++... gcc3
checking whether ln -s works... yes
checking for egrep... (cached) /usr/bin/grep -E
checking for pthread_create in -lpthread... no
configure: error:  You need to have libpthread installed to compile sngrep.

dunst0 avatar Dec 01 '17 09:12 dunst0

Give it a try to:

env CFLAGS="-O0 -g -I/usr/include -I/usr/local/include" LDFLAGS="-L/usr/lib -L/usr/local/lib" ./configure --enable-ipv6 --enable-eep --with-openssl --with-pcre

with -O0 -g in flags instead of using --enable-debug

Thanks!

Kaian avatar Dec 12 '17 12:12 Kaian

I'm not sure if the above commit fixes the problem, but It replaces one of the mentioned error prompts in my first response.

This change is required anyway for security reasons, but may not be the one cuasing the crash.

-            dialog_run(capture_last_error());
+            dialog_run("%s", capture_last_error());

Kaian avatar Dec 12 '17 14:12 Kaian

Hi I did some testing, first the bt full with debug info, with no update from source.

#0  0x00000008020b7633 in vfprintf_l () from /lib/libc.so.7
No symbol table info available.
#1  0x0000000802109086 in vsprintf () from /lib/libc.so.7
No symbol table info available.
#2  0x0000000000417d39 in dialog_run (fmt=0x0) at curses/ui_manager.c:484
	textva = 0x7fffffffcc20 ""
	ap = 0x7fffffffcc00
	height = 0
	width = 0
	win = (WINDOW *) 0x0
	word = 0x0
	col = 2
	line = 2
#3  0x0000000000425538 in save_to_file (ui=0x640e48) at curses/ui_save.c:470
	savepath = 0x7fffffffe230 "/root/"
	savefile = 0x7fffffffde30 "fs.pcap"
	fullfile = 0x7fffffffd630 "/root/fs.pcap"
	call = (sip_call_t *) 0x0
	msg = (sip_msg_t *) 0x0
	pd = (pcap_dumper_t *) 0x0
	f = (FILE *) 0x0
	cur = 0
	total = 0
	progress = (WINDOW *) 0x0
	calls = {current = 0, current_vector = 0, vector = 0x0, filter = 0}
	msgs = {current = 0, current_vector = 0, vector = 0x0, filter = 0}
	rtps = {current = 0, current_vector = 0, vector = 0x0, filter = 0}
	packets = {current = 0, current_vector = 0, vector = 0x0, filter = 0}
	packet = (packet_t *) 0x0
	sorted = (vector_t *) 0x0
	info = (save_info_t *) 0x8027af200
#4  0x000000000042509e in save_handle_key (ui=0x640e48, key=10) at curses/ui_save.c:354
	field_idx = 1
	action = 39
	info = (save_info_t *) 0x8027af200
#5  0x0000000000416456 in ui_handle_key (ui=0x640e48, key=10) at curses/ui_panel.c:149
	hld = -1
#6  0x00000000004171fe in ui_wait_for_input () at curses/ui_manager.c:236
	c = 10
	hld = -1
	ui = (ui_t *) 0x640e48
	win = (WINDOW *) 0x8026e9320
	panel = (PANEL *) 0x80262b640
#7  0x00000000004103fa in main (argc=4, argv=0x7fffffffeb20) at main.c:397
	long_options = 0x633220
	opt = -1
	idx = 0
	limit = 20000
	only_calls = 0
	no_incomplete = 1
	i = 3
	device = 0x6360b4 "any"
	outfile = 0x0
	bpf = 0x7fffffffe880 ""
	keyfile = 0x0
	match_expr = 0x1 <Address 0x1 out of bounds>
	match_insensitive = 0
	match_invert = 0
	no_interface = 0
	quiet = 0
	rtp_capture = 0
	rotate = 0
	no_config = 0
	infiles = (vector_t *) 0x80261c000
	indevices = (vector_t *) 0x80261c030
	options = 0x42aaa6 "hVd:I:O:pqtW:k:crl:ivNqDL:H:Rf:F"

And than I did git pull and get your changes. I get no longer a segfault but the dialog says just (null) and no file is saved.

dunst0 avatar Dec 18 '17 10:12 dunst0

Hi @dunst0

Thanks for the extra information and debugging effort! :+1:

I have noticed browsing the code that the save process only works when a single input source is used and it could be easily reproduced by simply opening 2 pcaps using -I command line twice and trying to save.

If that's the problem, this bug has been here since origin and the main cause is that the save process requires a single libpcap handle to create the savefile (so saving two inputs in a single file is not possible).

I'll try to do some tests to see if this limitation can be removed. Any further information and testing is appreciated.

Thanks!!

Kaian avatar Dec 18 '17 10:12 Kaian

Hi !

I've done some attempts to save multiple inputs into a single pcap using one of their handlers but it doesn't work: only some of the packets are saved correctly and the report dialog popup can not even determine if they've been properly saved or not.

In some scenarios, merging the packets seems possible. For example, when all the inputs share the same datalink type (p.e. all are ethernet cards), but others fail silently (p.e. capturing at the same time from ethernet card and linux cooked datalink).

I have disabled the save dialog when multiple input sources are specified (like using multiple -d or -I command line arguments) to avoid the crash or a misleading save count popup.

If you have time, please give it a try to the previous commit.

Also check the Capture mode in the first screen: If it has Offline: [multi] or Online: [multi] save won't be possible. If not, then drop me a line and I will debug more :)

Thanks for your time and testing @dunst0 !!

Kaian avatar Dec 22 '17 11:12 Kaian

This is already included in 1.4.5, please reopen if still crashing!

Kaian avatar Apr 05 '18 10:04 Kaian