diff --git a/usr.sbin/installboot/bootstrap.c b/usr.sbin/installboot/bootstrap.c index 7576b1cb5e4..9abb63823b8 100644 --- a/usr.sbin/installboot/bootstrap.c +++ b/usr.sbin/installboot/bootstrap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bootstrap.c,v 1.14 2025/09/17 16:12:10 deraadt Exp $ */ +/* $OpenBSD: bootstrap.c,v 1.15 2025/11/19 15:05:04 deraadt Exp $ */ /* * Copyright (c) 2013 Joel Sing @@ -112,12 +112,12 @@ bootstrap(int devfd, char *dev, char *bootfile) */ lp = (struct disklabel *)(boot + (LABELSECTOR * DEV_BSIZE) + LABELOFFSET); - for (i = 0, p = (char *)lp; i < (int)sizeof(*lp); i++) + for (i = 0, p = (char *)lp; i < dl16sz; i++) if (p[i] != 0) errx(1, "bootstrap has data in disklabel area"); /* Patch the disklabel into the bootstrap code. */ - memcpy(lp, &dl, sizeof(dl)); + memcpy(lp, &dl, dl16sz); /* Write the bootstrap out to the disk. */ if (verbose) diff --git a/usr.sbin/installboot/installboot.c b/usr.sbin/installboot/installboot.c index dbbd3309d32..cd6d692b46d 100644 --- a/usr.sbin/installboot/installboot.c +++ b/usr.sbin/installboot/installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.c,v 1.17 2025/02/19 21:30:46 kettenis Exp $ */ +/* $OpenBSD: installboot.c,v 1.18 2025/11/19 15:05:04 deraadt Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing @@ -16,11 +16,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#include #include #include #include #include #include +#include #include #include @@ -36,6 +39,14 @@ char *root; char *stage1; char *stage2; +/* + * XXX Only read the old smaller "skinny" label for now which + * has 16 partitions. offsetof() is used to carve struct disklabel. + * Later we'll add code to read and process the "fat" label with + * 52 partitions. + */ +size_t dl16sz = offsetof(struct disklabel, d_partitions[MAXPARTITIONS16]); + static __dead void usage(void) { diff --git a/usr.sbin/installboot/installboot.h b/usr.sbin/installboot/installboot.h index 5b460a63ab3..55256287747 100644 --- a/usr.sbin/installboot/installboot.h +++ b/usr.sbin/installboot/installboot.h @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.h,v 1.17 2025/02/19 21:30:46 kettenis Exp $ */ +/* $OpenBSD: installboot.h,v 1.18 2025/11/19 15:05:04 deraadt Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing * @@ -28,6 +28,8 @@ extern char *root; extern char *stage1; extern char *stage2; +extern size_t dl16sz; + #ifdef BOOTSTRAP void bootstrap(int, char *, char *); #endif diff --git a/usr.sbin/installboot/landisk_installboot.c b/usr.sbin/installboot/landisk_installboot.c index b8ed8ddbbae..e0440e6b196 100644 --- a/usr.sbin/installboot/landisk_installboot.c +++ b/usr.sbin/installboot/landisk_installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: landisk_installboot.c,v 1.13 2025/09/17 16:12:10 deraadt Exp $ */ +/* $OpenBSD: landisk_installboot.c,v 1.14 2025/11/19 15:05:04 deraadt Exp $ */ /* * Copyright (c) 2013 Joel Sing @@ -208,12 +208,12 @@ md_bootstrap(int devfd, char *dev, char *bootfile) */ lp = (struct disklabel *)(boot + (LABELSECTOR * DEV_BSIZE) + LABELOFFSET); - for (i = 0, p = (char *)lp; i < (int)sizeof(*lp); i++) + for (i = 0, p = (char *)lp; i < dl16sz; i++) if (p[i] != 0) errx(1, "bootstrap has data in disklabel area"); /* Patch the disklabel into the bootstrap code. */ - memcpy(lp, &dl, sizeof(dl)); + memcpy(lp, &dl, dl16sz); /* Write the bootstrap out to the disk. */ bootpos *= dl.d_secsize;