Date: Fri, 24 Aug 2012 09:34:29 -0600 From: John Hein <jhein@symmetricom.com> To: hackers@freebsd.org Subject: Re: LD_PRELOADed code before or after exec - different behavior after 6.x Message-ID: <20535.40709.486888.887048@gromit.timing.com> In-Reply-To: <20535.39682.330250.337503@gromit.timing.com> References: <20535.39682.330250.337503@gromit.timing.com>
next in thread | previous in thread | raw e-mail | index | archive | help
John Hein wrote at 09:17 -0600 on Aug 24, 2012:
>
> head sl.cc pe.c
> ==> sl.cc <==
> #include <cstdio>
> #include <cstdlib>
> class C
> {
> public:
> C(){
> printf("C\n");
> unsetenv("XXX");
> }
> };
> static C c;
>
> ==> pe.c <==
> #include <stdio.h>
> #include <stdlib.h>
> int
> main()
> {
> char *p=getenv("XXX");
> if (p != NULL)
> printf("XXX=%s\n",p);
> return 0;
> }
>
>
> % g++ -fpic -shared sl.cc -o sl.so
> % gcc pe.c -o pe
>
> 7.x & 8.x ...
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> C
> XXX=1
I meant to write:
7.x & 8.x ...
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
C
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
C
XXX=1
> 6.x & 4.x ...
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> C
and
6.x & 4.x ...
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
C
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
C
> In 6.x and earlier (fedora 16, too), the unsetenv clears the XXX env
> var apparently in time to affect the exec'd process. In 8.x & 9.x, it
> seems the environment is set and passed to the exec'd process and the
> LD_PRELOADed code does not affect that despite its best efforts.
>
> It seems to me that 6.x behavior is more correct, but I'm seeking
> opinions before contemplating if / how to put together a fix.
>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20535.40709.486888.887048>
