summaryrefslogtreecommitdiff
path: root/sys/lib
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2006-12-30 18:31:40 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2006-12-30 18:31:40 +0000
commitbca037263ff67c4c5aee75524e5e826762ba80b0 (patch)
tree1be65e50f78230b641f146665e782de8e5508c23 /sys/lib
parenta202825e560557e18de6afa8fcdbdfe9bed5315e (diff)
do not load unneeded stringtab sections; avoids backward seeking; from netbsd; tested by miod@ and martin@; deraadt@ ok
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libsa/loadfile.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/sys/lib/libsa/loadfile.c b/sys/lib/libsa/loadfile.c
index 1da87241d1e..7c3b8545718 100644
--- a/sys/lib/libsa/loadfile.c
+++ b/sys/lib/libsa/loadfile.c
@@ -1,5 +1,5 @@
/* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */
-/* $OpenBSD: loadfile.c,v 1.10 2005/07/13 21:28:02 mickey Exp $ */
+/* $OpenBSD: loadfile.c,v 1.11 2006/12/30 18:31:39 mickey Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -261,10 +261,8 @@ elf_exec(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
Elf_Shdr *shp;
Elf_Phdr *phdr;
Elf_Off off;
- int i;
size_t sz;
- int first;
- int havesyms;
+ int first, i, j;
paddr_t minp = ~0, maxp = 0, pos = 0;
paddr_t offset = marks[MARK_START], shpp, elfp;
@@ -370,15 +368,21 @@ elf_exec(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
* there are no symbol sections.
*/
off = roundup((sizeof(Elf_Ehdr) + sz), sizeof(long));
-
- for (havesyms = i = 0; i < elf->e_shnum; i++)
- if (shp[i].sh_type == SHT_SYMTAB)
- havesyms = 1;
-
for (first = 1, i = 0; i < elf->e_shnum; i++) {
- if (shp[i].sh_type == SHT_SYMTAB ||
- shp[i].sh_type == SHT_STRTAB) {
- if (havesyms && (flags & LOAD_SYM)) {
+ switch (shp[i].sh_type) {
+ case SHT_STRTAB:
+ for (j = 0; j < elf->e_shnum; j++)
+ if (shp[j].sh_type == SHT_SYMTAB &&
+ shp[j].sh_link == (unsigned)i)
+ goto havesym;
+ /* FALLTHROUGH */
+ default:
+ /* Not loading this, so zero out the offset. */
+ shp[i].sh_offset = 0;
+ break;
+ havesym:
+ case SHT_SYMTAB:
+ if (flags & LOAD_SYM) {
PROGRESS(("%s%ld", first ? " [" : "+",
(u_long)shp[i].sh_size));
if (lseek(fd, shp[i].sh_offset,
@@ -387,6 +391,7 @@ elf_exec(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
FREE(shp, sz);
return 1;
}
+printf("*");
if (READ(fd, maxp, shp[i].sh_size) !=
shp[i].sh_size) {
WARN(("read symbols"));
@@ -400,11 +405,13 @@ elf_exec(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
off += roundup(shp[i].sh_size, 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);
- if (havesyms && first == 0)
+ if (first == 0)
PROGRESS(("]"));
}
FREE(shp, sz);