l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2003 Jan 21 10:45

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] electric fence - error in man page? a bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] electric fence - error in man page? a bug?



hola lugod,

according to the electric fence man page, pages of dynamic memory
which are free'd are returned back to the heap from whence they came.
in other words, if you do nothing, efence won't detect access of free'd
dynamic memory.

the man page goes on to say that you can set the global

   extern int EF_PROTECT_FREE;

or the shell variable

   EF_PROTECT_FREE

to the value 1 to intercept free() and keep them allocated.  this allows
electric fence to catch read/write access to free'd memory.

in my little hello world program:

   #include <stdio.h>
   #include <stdlib.h>
   
   int main(void)
   {
      int *a = (int *) malloc( 3*sizeof(int) );
   
      for (int i = 0; i < 3; ++i)
         a[i] = i;
   
      free(a);
   
      printf("%d\n", a[1]);
      return 0;
   }

i've found that efence will cause a segfault on the read of free'd
memory, even though i never set EF_PROTECT_FREE to 1.  this is contrary
to what i understand from the man page.

in fact, i tried to explicitly set the int to 0:

   #include <stdio.h>
   #include <stdlib.h>
   extern int EF_PROTECT_FREE;
   
   int main(void)
   {
      EF_PROTECT_FREE = 0;
      int *a = (int *) malloc( 3*sizeof(int) );
   
      for (int i = 0; i < 3; ++i)
         a[i] = i;
   
      free(a);
   
      printf("%d\n", a[1]);
      return 0;
   }

and it still segfaults on the last printf() statement.   i also tried:

   export EF_PROTECT_FREE=0

and the printf() still segfaults.


perhaps i'm non understanding the manpage correctly, but it looks like
this is a bug in electric fence.  everything else i've read in the
manpage seems accurate.

comments?

pete

ps- quite a relevent question for tonight, considering the author of
efence.   :-)

-- 
First they ignore you, then they laugh at you, then they fight you,
then you win. -- Gandhi, being prophetic about Linux.

Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!