Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char small[32], big[128];
int i = 16;
if(strstr(argv[1], "t8")) { i = 8; }
if(strstr(argv[1], "t16")) { i = 16; }
if(strstr(argv[1], "t32")) { i = 32; }
if(strstr(argv[1], "t64")) { i = 64; }
if(strstr(argv[1], "t128")) { i = 128; }
memset(big, 'Z', sizeof(big));
snprintf(small, i, "%s", big);
printf("%s\n", small);
return 0;
}
That is the program I am running through the parent. As you can see, if the values are t64 or t128, the program crashes. I simply want to run that program 5 times with the 5 different values and be able to see the segmentation faults when they occur.
Code:
bash$ ./bvss t8
ZZZZZZZ
bash$ ./bvss t16
ZZZZZZZZZZZZZZZ
bash$ ./bvss t32
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
bash$ ./bvss t64
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Segmentation fault
bash$ ./bvss t128
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Segmentation fault
bash$
bash$ ./test
ZZZZZZZ
ZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
bash$
Code:
void run(char *bin, char *data)
{
if(fork() == 0)
{
if(execl(bin, bin, data, 0) == -1)
{
perror("execl");
_exit(1);
}
}
else
{
int pid, status;
pid = wait(&status);
}
}
.....
for(i = 0; i < 5; i++)
{
run(PATH, data);
}
See as I've explained my complete situation, I still can't get my code to work. I ask kindly for a solution.