Module Name: src
Committed By: kamil
Date: Wed Nov 6 13:07:32 UTC 2019
Modified Files:
src/sys/kern: subr_disk_mbr.c
Log Message:
Avoid unaligned pointer arithmetic in check_label_magic()
Replace the logic of calculating the address with with base + offset.
Reported by GCC8.
Reported-by: [email protected]
To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/subr_disk_mbr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_disk_mbr.c
diff -u src/sys/kern/subr_disk_mbr.c:1.51 src/sys/kern/subr_disk_mbr.c:1.52
--- src/sys/kern/subr_disk_mbr.c:1.51 Fri May 17 18:50:40 2019
+++ src/sys/kern/subr_disk_mbr.c Wed Nov 6 13:07:32 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $ */
+/* $NetBSD: subr_disk_mbr.c,v 1.52 2019/11/06 13:07:32 kamil Exp $ */
/*
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.52 2019/11/06 13:07:32 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -571,8 +571,11 @@ look_netbsd_part(mbr_args_t *a, mbr_part
static bool
check_label_magic(const struct disklabel *dlp, uint32_t diskmagic)
{
- return memcmp(&dlp->d_magic, &diskmagic, sizeof(diskmagic)) == 0 &&
- memcmp(&dlp->d_magic2, &diskmagic, sizeof(diskmagic)) == 0;
+
+ return memcmp((const char *)dlp + offsetof(struct disklabel, d_magic),
+ &diskmagic, sizeof(diskmagic)) == 0 &&
+ memcmp((const char *)dlp + offsetof(struct disklabel, d_magic2),
+ &diskmagic, sizeof(diskmagic)) == 0;
}
#ifdef DISKLABEL_EI