netsniff-ng / netsniff-ng

A Swiss army knife for your daily Linux network plumbing.
http://netsniff-ng.org
Other
1.24k stars 243 forks source link

mausezahn -x crashes #195

Closed teknoraver closed 4 years ago

teknoraver commented 6 years ago

backtrace:

$ sudo gdb -q -ex run --args mausezahn/mausezahn -x 2323
Reading symbols from mausezahn/mausezahn...done.
Starting program: /home/mcroce/src/netsniff-ng/mausezahn/mausezahn -x 2323
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Loadable section ".note.gnu.property" outside of ELF segments

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405336 in automops_delete_fields (amp=0x6cceb0) at staging/automops.c:798
798                     cur = cur->next;
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.27-30.fc28.x86_64 libcli-1.9.7-0.20160131gite60d4cc.fc28.x86_64 libnet-1.1.6-15.fc28.x86_64 libpcap-1.9.0-1.fc28.x86_64 libxcrypt-4.1.1-4.fc28.x86_64
(gdb) bt
#0  0x0000000000405336 in automops_delete_fields (amp=0x6cceb0) at staging/automops.c:798
#1  0x00000000004036b6 in automops_set_defaults (cur=0x6cceb0) at staging/automops.c:62
#2  0x000000000040356f in automops_init () at staging/automops.c:32
#3  0x0000000000406e6d in mz_cli_init () at staging/cli.c:28
#4  0x000000000042943b in getopts (argc=3, argv=0x7fffffffe4c8) at staging/mausezahn.c:819
#5  0x00000000004296fc in main (argc=3, argv=0x7fffffffe4c8) at staging/mausezahn.c:916
(gdb)
cubog3000 commented 5 years ago

Had a same problem. Looks it misses new_automops init.

   26 struct automops * automops_init(void)
   27 {
   28     // Create initial automops element:
   29     struct automops *new_automops = (struct automops*) malloc(sizeof(struct automops));
   30     memset(new_automops, 0x0, sizeof(struct automops)); <-- here
micrictor commented 4 years ago

Given the error flow, I believe it’s because the allocated memory for the automop strict is not guaranteed to be zero, due to the use of ‘malloc’ over ‘calloc’. https://github.com/netsniff-ng/netsniff-ng/blob/master/staging/automops.c#L29

This could make the non-NULL conditional protecting execution of ’automop_delete_fields’ pass, even though ‘fields’ is not actually a valid pointer.