From owner-cvs-all@FreeBSD.ORG Wed Oct 26 18:46:28 2005 Return-Path: X-Original-To: cvs-all@FreeBSD.org Delivered-To: cvs-all@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4778B16A41F; Wed, 26 Oct 2005 18:46:28 +0000 (GMT) (envelope-from wpaul@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 112C143D4C; Wed, 26 Oct 2005 18:46:28 +0000 (GMT) (envelope-from wpaul@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j9QIkRsa087701; Wed, 26 Oct 2005 18:46:27 GMT (envelope-from wpaul@repoman.freebsd.org) Received: (from wpaul@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j9QIkRIP087700; Wed, 26 Oct 2005 18:46:27 GMT (envelope-from wpaul) Message-Id: <200510261846.j9QIkRIP087700@repoman.freebsd.org> From: Bill Paul Date: Wed, 26 Oct 2005 18:46:27 +0000 (UTC) To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Cc: Subject: cvs commit: src/sys/compat/ndis pe_var.h subr_pe.c src/usr.sbin/ndiscvt ndiscvt.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2005 18:46:28 -0000 wpaul 2005-10-26 18:46:27 UTC FreeBSD src repository Modified files: sys/compat/ndis pe_var.h subr_pe.c usr.sbin/ndiscvt ndiscvt.c Log: 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 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 Revision Changes Path 1.14 +9 -0 src/sys/compat/ndis/pe_var.h 1.12 +13 -7 src/sys/compat/ndis/subr_pe.c 1.12 +2 -2 src/usr.sbin/ndiscvt/ndiscvt.c