Module Name:    src
Committed By:   maxv
Date:           Sat Jul  6 05:41:23 UTC 2019

Modified Files:
        src/sys/dev/dkwedge: dkwedge_apple.c

Log Message:
Add a condition in the loop. Otherwise there could be an infinite loop,
and we could also be wrongfully adding more wedges than necessary.
Arbitrarily limit the number of blocks to 512, like GPT.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/dkwedge/dkwedge_apple.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/dev/dkwedge/dkwedge_apple.c
diff -u src/sys/dev/dkwedge/dkwedge_apple.c:1.3 src/sys/dev/dkwedge/dkwedge_apple.c:1.4
--- src/sys/dev/dkwedge/dkwedge_apple.c:1.3	Thu Jan 19 00:44:40 2017
+++ src/sys/dev/dkwedge/dkwedge_apple.c	Sat Jul  6 05:41:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dkwedge_apple.c,v 1.3 2017/01/19 00:44:40 maya Exp $	*/
+/*	$NetBSD: dkwedge_apple.c,v 1.4 2019/07/06 05:41:23 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dkwedge_apple.c,v 1.3 2017/01/19 00:44:40 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dkwedge_apple.c,v 1.4 2019/07/06 05:41:23 maxv Exp $");
 
 #include <sys/param.h>
 #ifdef _KERNEL
@@ -143,10 +143,10 @@ static struct {
 static int
 dkwedge_discover_apple(struct disk *pdk, struct vnode *vp)
 {
-	size_t i;
+	size_t i, n;
 	int error;
 	void *buf;
-	uint32_t blocksize, offset, rsize;
+	uint32_t blocksize, blockcount, offset, rsize;
 	struct apple_drvr_map *am;
 	struct apple_part_map_entry *ae;
 	struct apple_blockzeroblock ab;
@@ -178,8 +178,17 @@ dkwedge_discover_apple(struct disk *pdk,
 		goto out;
 	}
 
+	/* XXX Clamp entries at 512 for now. */
+	blockcount = am->sbBlkCount;
+	if (blockcount > 512) {
+		aprint_error("%s: WARNING: clamping number of blocks to "
+		    "512 (was %u)\n", pdk->dk_name, blockcount);
+		blockcount = 512;
+	}
+
 	ae = buf;
-	for (offset = blocksize;; offset += rsize) {
+	offset = blocksize;
+	for (n = 0; n < blockcount; n++, offset += rsize) {
 		DPRINTF("%s: offset %x rsize %x\n", __func__, offset, rsize);
 		if ((error = dkwedge_read(pdk, vp, offset / DEV_BSIZE, buf,
 		    rsize)) != 0) {

Reply via email to