From acf574f63eb1a3b2cbdfd4e226dca120dbf27779 Mon Sep 17 00:00:00 2001 From: bjh21 Date: Tue, 31 Jul 2001 22:11:57 +0000 Subject: 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). --- sys/lib/libsa/loadfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sys') 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)); } -- cgit