> Date: Wed, 4 Jan 2017 20:03:49 +0100
> From: Stefan Sperling <[email protected]>
>
> On Wed, Jan 04, 2017 at 07:16:55PM +0100, Stefan Sperling wrote:
> > The diff below fixes the problem for me. As far as I can tell this
> > should work on both 512 and 4k disks. But I cannot test with a 4k disk.
>
> And let's check for alloc() failure. Suggested by Theo.
Makes sense to me.
> Index: softraid_amd64.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/stand/libsa/softraid_amd64.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 softraid_amd64.c
> --- softraid_amd64.c 24 Dec 2016 22:49:38 -0000 1.3
> +++ softraid_amd64.c 4 Jan 2017 18:59:45 -0000
> @@ -435,7 +435,7 @@ findopenbsd_gpt(struct sr_boot_volume *b
> const char openbsd_uuid_code[] = GPT_UUID_OPENBSD;
> struct gpt_partition gp;
> static struct uuid *openbsd_uuid = NULL, openbsd_uuid_space;
> - static u_char buf[4096];
> + u_char *buf;
>
> /* Prepare OpenBSD UUID */
> if (openbsd_uuid == NULL) {
> @@ -456,6 +456,12 @@ findopenbsd_gpt(struct sr_boot_volume *b
> *err = "disk sector > 4096 bytes\n";
> return (-1);
> }
> + buf = alloc(bv->sbv_secsize);
> + if (buf == NULL) {
> + *err = "out of memory\n";
> + return (-1);
> + }
> + bzero(buf, bv->sbv_secsize);
>
> /* LBA1: GPT Header */
> lba = 1;
> @@ -466,17 +472,20 @@ findopenbsd_gpt(struct sr_boot_volume *b
> /* Check signature */
> if (letoh64(gh.gh_sig) != GPTSIGNATURE) {
> *err = "bad GPT signature\n";
> + free(buf, bv->sbv_secsize);
> return (-1);
> }
>
> if (letoh32(gh.gh_rev) != GPTREVISION) {
> *err = "bad GPT revision\n";
> + free(buf, bv->sbv_secsize);
> return (-1);
> }
>
> ghsize = letoh32(gh.gh_size);
> if (ghsize < GPTMINHDRSIZE || ghsize > sizeof(struct gpt_header)) {
> *err = "bad GPT header size\n";
> + free(buf, bv->sbv_secsize);
> return (-1);
> }
>
> @@ -487,6 +496,7 @@ findopenbsd_gpt(struct sr_boot_volume *b
> gh.gh_csum = orig_csum;
> if (letoh32(orig_csum) != new_csum) {
> *err = "bad GPT header checksum\n";
> + free(buf, bv->sbv_secsize);
> return (-1);
> }
>
> @@ -514,6 +524,9 @@ findopenbsd_gpt(struct sr_boot_volume *b
> found = 1;
> }
> }
> +
> + free(buf, bv->sbv_secsize);
> +
> if (new_csum != letoh32(gh.gh_part_csum)) {
> *err = "bad GPT entries checksum\n";
> return (-1);
>
>