|
From: Jack <vm...@gm...> - 2015-05-25 11:26:47
|
Dear All
i am a rookie on valgrind
so i wrote an test program on pc to test valgrind ability of program internal memory breaking
but somehow it seems can't fetch program internal over-writing and under-writing global or local valuable??
following is my test program valtest.c , which will be compiled as valtest
if i run valgrind valtest swerr
with OVERWSTACK=1000 valgrind will catch internal memory breaking with msg
Addr 0x0 si not stack'd, malloc'd or free'd
but if i reduce OVERWSTACK=100 , no thing happened , valgrind will end in peace
if i set UNDERWSTACK=7, valgrind will catch out the breaking by msg addr 0xbe9c0097 is on thread1's stack , 1 bytes below stack pointer
but if i set UNDERWSTACK under 6 , its the same , no thing happened , valgrind will end in peace ,
it's the same , when i run valgrind valtest gwerr
if set OVERWGLOBAL 10000 , valgrind msg ->Addr 0x0 si not stack'd, malloc'd or free'd
but set OVERWGLOBAL 1000, valgrind will end in peace
if set UNDERWGLOBAL 1000 , valgrind msg ->jump to the invaild addr stated on the next line
but set UNDERWGLOBAL 10 , valgrind will end in peace
so could anyone kindlly direct me
how to configure valgrind to be able to catch out the internal memory breaking???
Thanks~~jack
void test(void);
char gArray[10];
void test(void){
char cmd[10];
#define OVERWSTACK 1000
#define UNDERWSTACK 7
for(i=0;i<OVERWSTACK;i++)
cmd[i]='\0';
for(i=1;i<= UNDERWSTACK;i++)
*((char *)cmd-i)='\0';
}
int main (int argc, char *argv[])
{
if( strcmp(argv[1],"swerr")==0 ){
printf("valtest:cmd swerr\n");
test();
}
else if( strcmp(argv[1],"gwerr")==0 ){
int i;
printf("valtest:cmd gwerr\n");
#define OVERWGLOBAL 10000
#define UNDERWGLOBAL 1000
for(i=0;i<OVERWGLOBAL;i++)
gArray[i]='\0';
for(i=0;i<UNDERWGLOBAL;i++)
*((char *)gArray-i)='\0';
}
}
|