diff --git a/sys/kern/subr_disk_mbr.c b/sys/kern/subr_disk_mbr.c index 7dee5c1b46ab..1ff8d3787c21 100644 --- a/sys/kern/subr_disk_mbr.c +++ b/sys/kern/subr_disk_mbr.c @@ -588,7 +588,7 @@ check_label_magic(const struct disklabel *dlp, uint32_t diskmagic) static int validate_label(mbr_args_t *a, uint label_sector) { - struct disklabel *dlp; + struct disklabel *dlp, tlp; char *dlp_lim, *dlp_byte; int error; #ifdef DISKLABEL_EI @@ -624,21 +624,23 @@ validate_label(mbr_args_t *a, uint label_sector) else dlp_byte += LABELSECTOR * a->lp->d_secsize; dlp = (void *)dlp_byte; + memcpy(&tlp, dlp, sizeof(tlp)); break; } - if (!check_label_magic(dlp, DISKMAGIC)) + memcpy(&tlp, dlp, sizeof(tlp)); + if (!check_label_magic(&tlp, DISKMAGIC)) #ifdef DISKLABEL_EI { - if (!check_label_magic(dlp, bswap32(DISKMAGIC))) + if (!check_label_magic(&tlp, bswap32(DISKMAGIC))) continue; /* * The label is in the other byte order. We need to * checksum before swapping the byte order. */ - npartitions = bswap16(dlp->d_npartitions); + npartitions = bswap16(tlp.d_npartitions); if (npartitions > MAXPARTITIONS || - dkcksum_sized(dlp, npartitions) != 0) + dkcksum_sized(&tlp, npartitions) != 0) goto corrupted; swapped = 1; @@ -646,8 +648,8 @@ validate_label(mbr_args_t *a, uint label_sector) #else continue; #endif - else if (dlp->d_npartitions > MAXPARTITIONS || - dkcksum(dlp) != 0) { + else if (tlp.d_npartitions > MAXPARTITIONS || + dkcksum(&tlp) != 0) { #ifdef DISKLABEL_EI corrupted: #endif @@ -661,11 +663,11 @@ corrupted: case READ_LABEL: #ifdef DISKLABEL_EI if (swapped) - swap_disklabel(a->lp, dlp); + swap_disklabel(a->lp, &tlp); else - *a->lp = *dlp; + *a->lp = tlp; #else - *a->lp = *dlp; + *a->lp = tlp; #endif if ((a->msg = convertdisklabel(a->lp, a->strat, a->bp, a->secperunit)) != NULL) @@ -677,12 +679,13 @@ corrupted: #ifdef DISKLABEL_EI /* DO NOT swap a->lp itself for later references. */ if (swapped) - swap_disklabel(dlp, a->lp); + swap_disklabel(&tlp, a->lp); else - *dlp = *a->lp; + tlp = *a->lp; #else - *dlp = *a->lp; + tlp = *a->lp; #endif + memcpy(dlp, &tlp, sizeof(tlp)); a->bp->b_oflags &= ~BO_DONE; a->bp->b_flags &= ~B_READ; a->bp->b_flags |= B_WRITE;