Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386/stand/lib Don't use a magic value. Define a li...



details:   https://anonhg.NetBSD.org/src/rev/4ea6199fe605
branches:  trunk
changeset: 345719:4ea6199fe605
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sun Jun 05 14:13:57 2016 +0000

description:
Don't use a magic value. Define a limit, and enforce it.

diffstat:

 sys/arch/i386/stand/lib/bootinfo.c |  11 ++++++++---
 sys/arch/i386/stand/lib/bootinfo.h |   4 +++-
 sys/arch/i386/stand/lib/exec.c     |   4 ++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diffs (59 lines):

diff -r 7677e9d378a8 -r 4ea6199fe605 sys/arch/i386/stand/lib/bootinfo.c
--- a/sys/arch/i386/stand/lib/bootinfo.c        Sun Jun 05 14:06:31 2016 +0000
+++ b/sys/arch/i386/stand/lib/bootinfo.c        Sun Jun 05 14:13:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootinfo.c,v 1.5 2008/12/14 18:46:33 christos Exp $    */
+/*     $NetBSD: bootinfo.c,v 1.6 2016/06/05 14:13:57 maxv Exp $        */
 
 /*
  * Copyright (c) 1997
@@ -40,6 +40,11 @@
        what->len = size;
        what->type = type;
 
-       if (bootinfo)
-               bootinfo->entry[bootinfo->nentries++] = vtophys(what);
+       if (bootinfo == NULL) {
+               return;
+       }
+       if (bootinfo->nentries >= BTINFO_MAX) {
+               panic("bootinfo too big");
+       }
+       bootinfo->entry[bootinfo->nentries++] = vtophys(what);
 }
diff -r 7677e9d378a8 -r 4ea6199fe605 sys/arch/i386/stand/lib/bootinfo.h
--- a/sys/arch/i386/stand/lib/bootinfo.h        Sun Jun 05 14:06:31 2016 +0000
+++ b/sys/arch/i386/stand/lib/bootinfo.h        Sun Jun 05 14:13:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootinfo.h,v 1.10 2013/11/18 03:52:45 jakllsch Exp $   */
+/*     $NetBSD: bootinfo.h,v 1.11 2016/06/05 14:13:57 maxv Exp $       */
 
 /*
  * Copyright (c) 1997
@@ -35,6 +35,8 @@
 
 extern struct bootinfo *bootinfo;
 
+#define BTINFO_MAX     32
+
 #define BI_ALLOC(max) (bootinfo = alloc(sizeof(struct bootinfo) \
                                         + ((max) - 1) * sizeof(uint32_t))) \
                       ->nentries = 0
diff -r 7677e9d378a8 -r 4ea6199fe605 sys/arch/i386/stand/lib/exec.c
--- a/sys/arch/i386/stand/lib/exec.c    Sun Jun 05 14:06:31 2016 +0000
+++ b/sys/arch/i386/stand/lib/exec.c    Sun Jun 05 14:13:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec.c,v 1.60 2016/06/05 14:06:31 maxv Exp $    */
+/*     $NetBSD: exec.c,v 1.61 2016/06/05 14:13:57 maxv Exp $    */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -356,7 +356,7 @@
               file ? file : "NULL", loadaddr);
 #endif
 
-       BI_ALLOC(32); /* ??? */
+       BI_ALLOC(BTINFO_MAX);
 
        BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
 



Home | Main Index | Thread Index | Old Index