summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2014-11-06 17:23:41 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2014-11-06 17:23:41 +0000
commit712b6c92222367886cb766c4106b9b875cd2eb66 (patch)
tree8ab8cfdd0a8fe1d3e61981743e483c2280e828b2
parent9009274316d7e53bd3c54bf07f6e9ecc96916a58 (diff)
Make better use of the value of psectionslen instead of recomputing
it multiple times. Also remove an unused variable. OK deraadt@ tedu@
-rw-r--r--sys/kern/exec_elf.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index 00a8069a8d1..fdb671a179d 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.c,v 1.102 2014/11/06 16:43:42 tedu Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.103 2014/11/06 17:23:40 millert Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
@@ -938,14 +938,13 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie)
return EPERM;
#else
Elf_Ehdr ehdr;
- Elf_Phdr phdr, *psections;
+ Elf_Phdr *psections = NULL;
struct countsegs_state cs;
struct writesegs_state ws;
off_t notestart, secstart, offset;
size_t notesize, psectionslen;
int error, i;
- psections = NULL;
/*
* We have to make a total of 3 passes across the map:
*
@@ -1000,16 +999,15 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie)
if (error)
goto out;
- offset = sizeof(ehdr);
-
- notestart = offset + sizeof(phdr) * cs.npsections;
- secstart = notestart + notesize;
-
psections = mallocarray(cs.npsections, sizeof(Elf_Phdr),
M_TEMP, M_WAITOK|M_ZERO);
psectionslen = cs.npsections * sizeof(Elf_Phdr);
printf("coredump: malloc %zu bytes at %p\n", psectionslen, psections);
+ offset = sizeof(ehdr);
+ notestart = offset + psectionslen;
+ secstart = notestart + notesize;
+
/* Pass 2: now write the P-section headers. */
ws.secoff = secstart;
ws.psections = psections;
@@ -1028,13 +1026,12 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie)
ws.psections->p_flags = PF_R;
ws.psections->p_align = ELFROUNDSIZE;
- error = coredump_write(cookie, UIO_SYSSPACE, psections,
- cs.npsections * sizeof(Elf_Phdr));
+ error = coredump_write(cookie, UIO_SYSSPACE, psections, psectionslen);
if (error)
goto out;
#ifdef DIAGNOSTIC
- offset += cs.npsections * sizeof(Elf_Phdr);
+ offset += psectionslen;
if (offset != notestart)
panic("coredump: offset %lld != notestart %lld",
(long long) offset, (long long) notestart);