Subject: lib/6156: nlist returns bogus value if symbol is multiple defined in object
To: None <gnats-bugs@gnats.netbsd.org>
From: Stefan Grefen <grefen@hprc.tandem.com>
List: netbsd-bugs
Date: 09/14/1998 20:21:11
>Number: 6156
>Category: lib
>Synopsis: nlist returns bogus value if symbol is multiple defined in object
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Sep 14 11:35:00 1998
>Last-Modified:
>Originator: Stefan Grefen
>Organization:
Stefan Grefen Tandem Computers Europe Inc.
grefen@hprc.tandem.com High Performance Research Center
--- Hacking's just another word for nothing left to kludge. ---
>Release: 12 Sep 1998
>Environment:
NetBSD hicks 1.3H NetBSD 1.3H (CPQ) #52: Mon Sep 14 17:44:39 CEST 1998 grefen@hicks:/usr/src/sys/arch/i386/compile/CPQ i386
>Description:
nlist counts a symbol every time it finds it in the object, this gives
bogus return value;
>How-To-Repeat:
try look for gcc_compiled using nlist in a binary
>Fix:
a.out fix only !!
*** /usr/sup/src/lib/libc/gen/nlist_aout.c Wed Jul 1 13:11:28 1998
--- /usr/src/lib/libc/gen/nlist_aout.c Mon Sep 14 18:38:07 1998
***************
*** 71,76 ****
--- 71,77 ----
struct nlist nbuf[1024];
struct exec exec;
struct stat st;
+ char *scoreboard,*scored;
if (pread(fd, &exec, sizeof(exec), (off_t)0) != sizeof(exec) ||
N_BADMAG(exec) || fstat(fd, &st) < 0)
***************
*** 116,121 ****
--- 117,127 ----
}
if (lseek(fd, symoff, SEEK_SET) == -1)
return (-1);
+ if ((scoreboard = alloca(nent)) == NULL ) {
+ return (-1);
+ }
+
+ bzero(scoreboard,nent);
while (symsize > 0) {
cc = MIN(symsize, sizeof(nbuf));
***************
*** 127,138 ****
if (soff == 0 || (s->n_type & N_STAB) != 0)
continue;
! for (p = list; !ISLAST(p); p++)
! if (!strcmp(&strtab[soff], p->n_un.n_name)) {
p->n_value = s->n_value;
p->n_type = s->n_type;
p->n_desc = s->n_desc;
p->n_other = s->n_other;
if (--nent <= 0)
break;
}
--- 133,148 ----
if (soff == 0 || (s->n_type & N_STAB) != 0)
continue;
! for (p = list, scored = scoreboard;
! !ISLAST(p);
! p++, scored++)
! if ( !*scored &&
! !strcmp(&strtab[soff], p->n_un.n_name)) {
p->n_value = s->n_value;
p->n_type = s->n_type;
p->n_desc = s->n_desc;
p->n_other = s->n_other;
+ *scored = 1;
if (--nent <= 0)
break;
}
>Audit-Trail:
>Unformatted: