summaryrefslogtreecommitdiff
path: root/sys/lib
diff options
context:
space:
mode:
authorbjh21 <bjh21@NetBSD.org>2001-07-31 22:11:57 +0000
committerbjh21 <bjh21@NetBSD.org>2001-07-31 22:11:57 +0000
commitacf574f63eb1a3b2cbdfd4e226dca120dbf27779 (patch)
tree5170d52f37a0db12457fad247cac59a7f448e872 /sys/lib
parent1af74c304df84405008369257392a45d2a027865 (diff)
When loading ELF, zero out:
The e_shstrndx field in the ELF header, since we don't load .shstrtab. The sh_name field in each section header, for the same reason. The sh_offset field for any section we don't load. This means the kernel has some chance of knowing what it's being given. It also means that the behaviour of old kernels with new loaders should be deterministic (if not terribly useful: they still can't find the symbol table).
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libsa/loadfile.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/sys/lib/libsa/loadfile.c b/sys/lib/libsa/loadfile.c
index fd164583b17..a6ccee99d1b 100644
--- a/sys/lib/libsa/loadfile.c
+++ b/sys/lib/libsa/loadfile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile.c,v 1.16 2001/07/31 21:09:52 bjh21 Exp $ */
+/* $NetBSD: loadfile.c,v 1.17 2001/07/31 22:11:57 bjh21 Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -382,6 +382,10 @@ elf_exec(fd, elf, marks, flags)
if (shp[j].sh_type == SHT_SYMTAB &&
shp[j].sh_link == i)
goto havesym;
+ /* FALLTHROUGH */
+ default:
+ /* Not loading this, so zero out the offset. */
+ shp[i].sh_offset = 0;
break;
havesym:
case SHT_SYMTAB:
@@ -406,6 +410,8 @@ elf_exec(fd, elf, marks, flags)
sizeof(long));
first = 0;
}
+ /* Since we don't load .shstrtab, zero the name. */
+ shp[i].sh_name = 0;
}
if (flags & LOAD_SYM) {
BCOPY(shp, shpp, sz);
@@ -425,6 +431,7 @@ elf_exec(fd, elf, marks, flags)
elf->e_shoff = sizeof(Elf_Ehdr);
elf->e_phentsize = 0;
elf->e_phnum = 0;
+ elf->e_shstrndx = SHN_UNDEF;
BCOPY(elf, elfp, sizeof(*elf));
}