Hello,
When i run my program it shows just segmentation fault. As my knowledge, segmentation fault can occur for pointer and memory related fault. But i could not find out my mistake. Please see some part of code(maybe, that is related to segmentation fault):

char *state_in;
//state_in = malloc(1024);
char pls[] = "./faultinjectors/fi_";
   strcat(pls, argv[1]);
   strcat(pls, ".so");
   const char* preloadStr =  pls;
   strcpy(state_in, argv[1]);
....
...
setenv("LD_PRELOAD", preloadStr, 1);
...
...

I think above part of my code are related to segmentation fault.

Could anybody know me where is my mistake?

Recommended Answers

All 5 Replies

It is always a good idea to run your code in the debugger.
Meanwhile, a line 3 allocates just as much memory as needed to hold the initializing string. An attempt to catenate something to it results in some stack portion corruption, overwriting most likely the state_in (even if you initialize it correctly, lines 4 and 5 will make it a garbage pointer). Then the segfault at line 7 is imminent.

I am still in problem. i could not solve the segmentation fault. could anybody know me in more details?

I am still in problem. i could not solve the segmentation fault. could anybody know me in more details?

Could you post your updated code..So we can see what you changed.

Run it through a debugger
assuming you are using gcc

$gcc -ggdb file.c
$gdb ./a.out
$run
$bt

This will tell you on which line the error originated.

You can also look into valgrind

good luck

Run it through a debugger
assuming you are using gcc


This will tell you on which line the error originated.

You can also look into valgrind

good luck

When i used $gcc -ggdb command, it shown "-ggdb command not found". I am new in gcc. please help me how to recover and debug my program. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.