segfault if I call func from a lib, why?

hi every1,
perhaps some one be able to help me in that worst deal...
actually I use libiptc & libxtables from netfilter project and have got this trace....
it happening every time if I do to call function from those libraries, e.g xtables_error(), xtables_find_target(), add_command() and any other..., but unfortunately everywhere I has segfault.
1
2
3
4
5
6
7
8
9
10
11
12
==21005== Invalid read of size 4
==21005==    at 0x4050D4B: xtables_find_target (xtables.c:626)
==21005==    by 0x804C723: main (in /home/quant/table)
==21005==  Address 0x4 is not stack'd, malloc'd or (recently) free'd
==21005==
==21005== Process terminating with default action of signal 11 (SIGSEGV)
==21005==  Access not within mapped region at address 0x4
==21005==    at 0x4050D4B: xtables_find_target (xtables.c:626)
==21005==    by 0x804C723: main (in /home/quant/table)
--21005-- REDIR: 0x40c4790 (free) redirected to 0x4022ad0 (free)
==21005==
==21005== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 19 from 1) 

there... how i do configuration libs after building and installation.
./configure --prefix=/usr/local --enable-devel --enable-libipq --enable-static
are you allocating memory when reading ?
you have to post some code to get some replies.
allocation for what I should do?
gcc -Wall -ggdb -o table -I/usr/iptables-1.4.4/include/ -L/usr/iptables-1.4.4/lib/ -liptc -lxtables iptest.c
valgrind -v --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp ./table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <limits.h>
#include <unistd.h>
#include <iptables.h>
#include <xtables.h>
#include <fcntl.h>
#include <sys/utsname.h>
int main(void){
printf("first\n");
xtables_error(PARAMETER_PROBLEM, "well done");
printf("second\n");
exit(1);
}


function and parameters contains in this header
xtables.h
1
2
3
4
5
6
7
8
9
10
11
enum xtables_exittype {
        OTHER_PROBLEM = 1,
        PARAMETER_PROBLEM,
        VERSION_PROBLEM,
        RESOURCE_PROBLEM,
        XTF_ONLY_ONCE,
        XTF_NO_INVERT,
        XTF_BAD_VALUE,
        XTF_ONE_ACTION,
};
#define xtables_error (xt_params->exit_err) 
Last edited on
if this is the code in which you are getting errors, i want to know if "xt_params" is initializing somewhere before the code enters main? because if its not then it will fault. Rest the program looks ok..
closed, I made it without xtables lib ;)
Last edited on
Topic archived. No new replies allowed.