Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: [Wireshark-dev] wiretap function wtap_open_offline fails with SIGSEGV

Date Prev · Date Next · Thread Prev · Thread Next
From: Martin Sehnoutka <msehnout@xxxxxxxxxx>
Date: Thu, 3 May 2018 10:38:00 +0200
Hi,

I'm trying to write a simple program with the wiretap API just to test
how it works, but I'm struggling with the function wtap_open_offline.
Here is what the code looks like:

#include <glib.h>
#include <iostream>
#include <cassert>
#include <wireshark/wiretap/wtap.h>

using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
    if (argc < 2) {
        fprintf(stderr,
            "Dump filename missing!\n\n"
            "Usage: %s dump_filename\n\n", (const char*) argv[0]);
        exit(1);
    }
    cout << "Test wiretap drop_count: " << argv[1] << endl;
    int err = 0;
    gchar* err_info = NULL;
    wtap* wth = wtap_open_offline(argv[1], WTAP_TYPE_AUTO, &err,
&err_info, FALSE);
    if (err != 0) {
	    printf("Error: %d, %s", err, err_info);
	    exit(1);
    }
    assert(wth);
    wtap_close(wth);

    return 0;
}

As far as I was able to understand the documentation comments, it takes
a file name, a type which is only defined for AUTO, two error pointers
and a boolean value. But when I try to run the code, it fails with SIGSEGV.

$ gdb reproducer
(gdb) run ../dump.pcapng
...

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b6e268 in wtap_block_create
(block_type=block_type@entry=WTAP_BLOCK_NG_SECTION)
    at wtap_opttypes.c:191
191	    block->info->create(block);
(gdb) bt
#0  0x00007ffff7b6e268 in wtap_block_create
(block_type=block_type@entry=WTAP_BLOCK_NG_SECTION)
    at wtap_opttypes.c:191
#1  0x00007ffff7b3e531 in wtap_open_offline (filename=<optimized out>,
type=0, err=0x7fffffffe3d4,
    err_info=0x7fffffffe3c8, do_random=0) at file_access.c:837
#2  0x0000000000400be0 in main (argc=2, argv=0x7fffffffe4c8) at
../main.cpp:21

Any ideas what goes wrong here? It fails on a function call, that takes
a predefined value, that I cannot influence.

Regards,
-- 
Martin Sehnoutka | Associate Software Engineer
PGP: 5FD64AF5
UTC+1 (CET)
RED HAT | TRIED. TESTED. TRUSTED.

Attachment: signature.asc
Description: OpenPGP digital signature