dynamic linker problem

From: Kimura Fuyuki <fuyuki_at_nigredo.org>
Date: Sat, 14 Feb 2004 11:03:37 +0900
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_at_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
Received on Fri Feb 13 2004 - 17:03:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:43 UTC