Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Nov 2009 14:46:44 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        marcel@freebsd.org
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r199274 - head/sys/nfsserver
Message-ID:  <20091114.144644.580455928.imp@bsdimp.com>
In-Reply-To: <200911141814.nAEIE7ku008530@svn.freebsd.org>
References:  <200911141814.nAEIE7ku008530@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <200911141814.nAEIE7ku008530@svn.freebsd.org>
            Marcel Moolenaar <marcel@FreeBSD.org> writes:
: Author: marcel
: Date: Sat Nov 14 18:14:07 2009
: New Revision: 199274
: URL: http://svn.freebsd.org/changeset/base/199274
: 
: Log:
:   Fix an obvious panic by not casting from a pointer that is 4-bytes
:   alignment to a type that needs 8-byte alignment, and thus causing
:   misaligned memory references.
:   
:   MFC after:	1 week
: 
: Modified:
:   head/sys/nfsserver/nfs_fha.c
: 
: Modified: head/sys/nfsserver/nfs_fha.c
: ==============================================================================
: --- head/sys/nfsserver/nfs_fha.c	Sat Nov 14 16:20:07 2009	(r199273)
: +++ head/sys/nfsserver/nfs_fha.c	Sat Nov 14 18:14:07 2009	(r199274)
: @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
:  #include <sys/systm.h>
:  #include <sys/sysproto.h>
:  #include <sys/kernel.h>
: +#include <sys/endian.h>
:  #include <sys/sysctl.h>
:  #include <sys/vnode.h>
:  #include <sys/malloc.h>
: @@ -206,7 +207,11 @@ fha_extract_info(struct svc_req *req, st
:  	if (error)
:  		goto out;
:  
: -	i->fh = *(const u_int64_t *)(fh.fh_generic.fh_fid.fid_data);
: +#if _BYTE_ORDER == _LITTLE_ENDIAN
: +	i->fh = le64dec(fh.fh_generic.fh_fid.fid_data);
: +#else
: +	i->fh = be64dec(fh.fh_generic.fh_fid.fid_data);
: +#endif
:  
:  	/* Content ourselves with zero offset for all but reads. */
:  	if (procnum != NFSPROC_READ)

Wouldn't memcpy do the same thing without the need for an ifdef?

	memcpy(&i->fh, fh.fh_generic.fh_fid.fid_data, sizeof(uint64_t));

Warner




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091114.144644.580455928.imp>