Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/dkwedge Add a condition in the loop. Otherwise there...



details:   https://anonhg.NetBSD.org/src/rev/d605191e5725
branches:  trunk
changeset: 842479:d605191e5725
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Jul 06 05:41:23 2019 +0000

description:
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.

diffstat:

 sys/dev/dkwedge/dkwedge_apple.c |  19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r c9b884a5f8d3 -r d605191e5725 sys/dev/dkwedge/dkwedge_apple.c
--- a/sys/dev/dkwedge/dkwedge_apple.c   Sat Jul 06 05:13:10 2019 +0000
+++ b/sys/dev/dkwedge/dkwedge_apple.c   Sat Jul 06 05:41:23 2019 +0000
@@ -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 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 @@
                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) {



Home | Main Index | Thread Index | Old Index