Subject: lib/10940: Writing to dlopened library variable core with i386/a.out
To: None <gnats-bugs@gnats.netbsd.org>
From: Nick Hudson <nick@go61923.e-ly.com>
List: netbsd-bugs
Date: 09/03/2000 08:57:13
>Number:         10940
>Category:       lib
>Synopsis:       Writing to dlopened library variable core with i386/a.out
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 03 08:58:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Nick Hudson
>Release:        NetBSD-1.4.2
>Organization:
>Environment:
	
System: NetBSD go61923 1.4.2 NetBSD

>Description:
	The attached shar includes a program that cores on i386/a.out, but not
	on i386/ELF.
>How-To-Repeat:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	.
#	./Makefile
#	./dltest
#	./dltest/main.c
#	./dltest/Makefile
#	./libfoo
#	./libfoo/foo1.c
#	./libfoo/Makefile
#	./libfoo/shlib_version
#
echo c - .
mkdir -p . > /dev/null 2>&1
echo x - ./Makefile
sed 's/^X//' >./Makefile << 'END-of-./Makefile'
XSUBDIR=	libfoo dltest
X
Xall:
X	dltest/dltest
X
X.include <bsd.subdir.mk>
END-of-./Makefile
echo c - ./dltest
mkdir -p ./dltest > /dev/null 2>&1
echo x - ./dltest/main.c
sed 's/^X//' >./dltest/main.c << 'END-of-./dltest/main.c'
X#include <dlfcn.h>
X#include <stdio.h>
X
X#ifdef __ELF__
X#define FUNC "func"
X#define VAR "var"
X#else
X#define FUNC "_func"
X#define VAR "_var"
X#endif
X
Xint
Xmain ()
X{
X  void * handle;	
X  void (*pfunc)() = 0;
X  int *pvar = 0;
X
X  handle = dlopen("./libfoo/libfoo.so.3.2", RTLD_GLOBAL | RTLD_LAZY);
X  if (!handle) {
X    fprintf (stderr, "can't open the module!\n");
X    fprintf (stderr, "error was: %s\n", dlerror());
X    exit(1);
X  }
X
X  pfunc = (void(*)())dlsym(handle, FUNC);  
X  if (pfunc)
X      (*pfunc) ();
X  else {
X      fprintf (stderr, "did not find the `func' function\n");
X      fprintf (stderr, "error was: %s\n", dlerror());
X      exit(1);
X  }
X
X  pvar = (int*)dlsym(handle, VAR);  
X  /* Try assigning to the var variable. */
X  if (pvar)
X    *pvar = 1;
X  else {
X      fprintf (stderr, "did not find the `var' variable\n");
X      fprintf (stderr, "error was: %s\n", dlerror());
X      exit(1);
X  }
X  return 0;
X}
END-of-./dltest/main.c
echo x - ./dltest/Makefile
sed 's/^X//' >./dltest/Makefile << 'END-of-./dltest/Makefile'
XPROG=		dltest
X
XSRCS=		main.c
XCPPFLAGS+=	-I${.CURDIR}/../libfoo
XLDFLAGS+=	-L${.CURDIR}/../libfoo
XCFLAGS+=	-g
X
XMKMAN=		no
X
X.include <bsd.prog.mk>
END-of-./dltest/Makefile
echo c - ./libfoo
mkdir -p ./libfoo > /dev/null 2>&1
echo x - ./libfoo/foo1.c
sed 's/^X//' >./libfoo/foo1.c << 'END-of-./libfoo/foo1.c'
X#include <stdio.h>
X
X/* Give a global variable definition. */
Xint var;
X
Xvoid
Xfunc()
X{
X  printf ("** This is func **\n");
X}
END-of-./libfoo/foo1.c
echo x - ./libfoo/Makefile
sed 's/^X//' >./libfoo/Makefile << 'END-of-./libfoo/Makefile'
XLIB=	foo
XSRCS=	foo1.c
X
XCFLAGS+=	-g
X
X.include <bsd.lib.mk>
END-of-./libfoo/Makefile
echo x - ./libfoo/shlib_version
sed 's/^X//' >./libfoo/shlib_version << 'END-of-./libfoo/shlib_version'
Xmajor=3
Xminor=2
END-of-./libfoo/shlib_version
exit

>Fix:
	Unknown.
>Release-Note:
>Audit-Trail:
>Unformatted: