aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ndiscvt/ndiscvt.c
diff options
context:
space:
mode:
authorBill Paul <wpaul@FreeBSD.org>2005-10-26 18:46:27 +0000
committerBill Paul <wpaul@FreeBSD.org>2005-10-26 18:46:27 +0000
commit51d6d0952bcbf7971ece8d5f142ae296a9fd02e9 (patch)
tree0c397977232cbc0777c9a022d4281e7efd4c59c8 /usr.sbin/ndiscvt/ndiscvt.c
parent90e2fc863a95ebc1fc12ae656dbbc42c16e17a83 (diff)
downloadsrc-51d6d0952bcbf7971ece8d5f142ae296a9fd02e9.tar.gz
src-51d6d0952bcbf7971ece8d5f142ae296a9fd02e9.zip
Clean up and apply the fix for PR 83477. The calculation for locating
the start of the section headers has to take into account the fact that the image_nt_header is really variable sized. It happens that the existing calculation is correct for _most_ production binaries produced by the Windows DDK, but if we get a binary with oddball offsets, the PE loader could crash. Changes from the supplied patch are: - We don't really need to use the IMAGE_SIZEOF_NT_HEADER() macro when computing how much of the header to return to callers of pe_get_optional_header(). While it's important to take the variable size of the header into account in other calculations, we never actually look at anything outside the non-variable portion of the header. This saves callers from having to allocate a variable sized buffer off the heap (I purposely tried to avoid using malloc() in subr_pe.c to make it easier to compile in both the -D_KERNEL and !-D_KERNEL case), and since we're copying into a buffer on the stack, we always have to copy the same amount of data or else we'll trash the stack something fierce. - We need <stddef.h> to get offsetof() in the !-D_KERNEL case. - ndiscvt.c needs the IMAGE_FIRST_SECTION() macro too, since it does a little bit of section pre-processing. PR: kern/83477
Notes
Notes: svn path=/head/; revision=151703
Diffstat (limited to 'usr.sbin/ndiscvt/ndiscvt.c')
-rw-r--r--usr.sbin/ndiscvt/ndiscvt.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.sbin/ndiscvt/ndiscvt.c b/usr.sbin/ndiscvt/ndiscvt.c
index 090f0834f660..80eae836f080 100644
--- a/usr.sbin/ndiscvt/ndiscvt.c
+++ b/usr.sbin/ndiscvt/ndiscvt.c
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <net/if.h>
#include <stdlib.h>
+#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
@@ -88,8 +89,7 @@ extern const char *__progname;
#define SET_HDRS(x) \
dos_hdr = (image_dos_header *)x; \
nt_hdr = (image_nt_header *)(x + dos_hdr->idh_lfanew); \
- sect_hdr = (image_section_header *)((vm_offset_t)nt_hdr + \
- sizeof(image_nt_header));
+ sect_hdr = IMAGE_FIRST_SECTION(nt_hdr);
static
int insert_padding(imgbase, imglen)