kern/106646: [patch] Pointer incorrectly cast to ulong
Peter Jeremy
peterjeremy at optushome.com.au
Tue Dec 12 10:22:30 PST 2006
>Number: 106646
>Category: kern
>Synopsis: [patch] Pointer incorrectly cast to ulong
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Dec 12 18:20:02 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator: Peter Jeremy
>Release: FreeBSD 6.2-PRERELEASE amd64
>Organization:
n/a
>Environment:
System: FreeBSD turion.vk2pj.dyndns.org 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #23: Fri Oct 27 09:36:46 EST 2006 root at turion.vk2pj.dyndns.org:/usr/obj/usr/src/sys/turion amd64
The problem also appears in the latest 7-current source
>Description:
sys/nfs/nfs_common.h defines a macro nfsm_aligned()
to test if a particular address is sufficiently aligned
for the architecture. It does this by casting the address
to u_long. For portability, it should cast to intptr_t.
The existing code will fail on an architecture with strict
alignment where sizeof(void *) > sizeof(u_long)
>How-To-Repeat:
Code inspection
>Fix:
The following (untested) patch should work
Index: sys/nfs/nfs_common.h
===================================================================
RCS file: /usr/ncvs/src/sys/nfs/nfs_common.h,v
retrieving revision 1.38
diff -u -r1.38 nfs_common.h
--- sys/nfs/nfs_common.h 14 Jul 2005 20:08:26 -0000 1.38
+++ sys/nfs/nfs_common.h 12 Dec 2006 18:02:19 -0000
@@ -130,7 +130,7 @@
#ifdef __NO_STRICT_ALIGNMENT
#define nfsm_aligned(p, t) 1
#else
-#define nfsm_aligned(p, t) ((((u_long)(p)) & (sizeof(t) - 1)) == 0)
+#define nfsm_aligned(p, t) ((((intptr_t)(p)) & (sizeof(t) - 1)) == 0)
#endif
#endif
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list