Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Feb 2004 11:03:37 +0900
From:      Kimura Fuyuki <fuyuki@nigredo.org>
To:        freebsd-current@freebsd.org
Cc:        jdp@polstra.com
Subject:   dynamic linker problem
Message-ID:  <86isiaa03q.wl%fuyuki@nigredo.org>
In-Reply-To: <86n07oa7sa.wl%fuyuki@nigredo.org>
References:  <86n07oa7sa.wl%fuyuki@nigredo.org>

next in thread | previous in thread | raw e-mail | index | archive | help
OK, I more clearly point out the problem; run the following test and
think that behavior is secure/modular/comfortable or not.

BEGIN--cut here--cut here
#!/bin/sh

cat <<'[EOF]' >crypt.c
/* Define this function since I want to do so! */
char *crypt_md5(const char *pw, const char *salt)
{
	return "imbogus";
}
[EOF]

cat <<'[EOF]' >dltest.c
#include <stdio.h>
#include <dlfcn.h>

int main(void)
{
	void *h;
	char *(*crypt)(const char *, const char *);

	h = dlopen("/lib/libcrypt.so", 0);
        crypt = dlsym(h, "crypt");
 	printf("%s\n", crypt("imthekey", "$1$salt"));
}
[EOF]

cc -shared -o crypt.so crypt.c

# Link against crypt.so since I want to do so!
cc dltest.c -o dltest ./crypt.so
./dltest
END--cut here--cut here

At Thu, 12 Feb 2004 19:53:09 +0900,
Kimura Fuyuki <fuyuki@nigredo.org> wrote:
> 
> Someone please run the test below and tell me why dltest[12] show the
> different results on my 5.2.1-RC2 box. At least NetBSD 1.5.2 and some
> sort of Linux pass the test.
> 
> #!/bin/sh
> 
> cat <<[EOF] >shared.c
> double sin(double d) {return 9;}
> double faked_sin(double d) {return sin(d);}
> [EOF]
> 
> cat <<[EOF] >dltest.c
> #include <stdio.h>
> #include <dlfcn.h>
> 
> int main(void)
> {
> 	void *h;
> 	double (*faked_sin)(double);
> 
> 	h = dlopen("./shared.so", RTLD_LAZY);
>         faked_sin = dlsym(h, "faked_sin");
> 	printf("%f\n", faked_sin(0));
> }
> [EOF]
> 
> cc -shared -o shared.so shared.c
> 
> cc dltest.c -o dltest1
> ./dltest1 >result1
> 
> cc dltest.c -o dltest2 -lm
> ./dltest2 >result2
> 
> if diff result1 result2 >/dev/null; then
>         echo "You are very talented."
> else
> 	echo "Please tell me what's happening!"
> fi

-- fuyuki



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86isiaa03q.wl%fuyuki>