Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc/stand Do not rely on strings to which pointer...



details:   https://anonhg.NetBSD.org/src/rev/0e9e5c5e1a73
branches:  trunk
changeset: 580514:0e9e5c5e1a73
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Apr 27 07:59:47 2005 +0000

description:
Do not rely on strings to which pointers are returned by promlib functions
to persist accross further promlib calls.
This fixes (at least) bootjs.net.

diffstat:

 sys/arch/sparc/stand/boot/boot.c      |  27 +++++++++++++++------------
 sys/arch/sparc/stand/common/promdev.c |   6 +++---
 sys/arch/sparc/stand/common/promdev.h |   7 +++++--
 3 files changed, 23 insertions(+), 17 deletions(-)

diffs (121 lines):

diff -r b466feb9feaf -r 0e9e5c5e1a73 sys/arch/sparc/stand/boot/boot.c
--- a/sys/arch/sparc/stand/boot/boot.c  Wed Apr 27 07:48:02 2005 +0000
+++ b/sys/arch/sparc/stand/boot/boot.c  Wed Apr 27 07:59:47 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.19 2004/04/08 07:35:34 pk Exp $ */
+/*     $NetBSD: boot.c,v 1.20 2005/04/27 07:59:47 martin Exp $ */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -235,7 +235,7 @@
 main()
 {
        int     error, i;
-       char    *kernel;
+       char    kernel[MAX_PROM_PATH], *k;
        u_long  marks[MARK_MAX], bootinfo;
        struct btinfo_symtab bi_sym;
        void    *arg;
@@ -258,17 +258,20 @@
        /*
         * get default kernel.
         */
-       prom_bootdevice = prom_getbootpath();
-       kernel = prom_getbootfile();
-       boothowto = bootoptions(prom_getbootargs());
-
-       if (kernel != NULL && *kernel != '\0') {
+       k = prom_getbootfile();
+       if (k != NULL && *k != '\0') {
                i = -1; /* not using the kernels */
+               strcpy(kernel, k);
        } else {
                i = 0;
-               kernel = kernels[i];
+               strcpy(kernel, kernels[i]);
        }
 
+       k = prom_getbootpath();
+       if (k && *k)
+               strcpy(prom_bootdevice, k);
+       boothowto = bootoptions(prom_getbootargs());
+
        for (;;) {
                /*
                 * ask for a kernel first ..
@@ -280,15 +283,15 @@
                        if (strcmp(dbuf, "halt") == 0)
                                _rtt();
                        if (dbuf[0])
-                               prom_bootdevice = dbuf;
+                               strcpy(prom_bootdevice, dbuf);
                        printf("boot (press RETURN to try default list): ");
                        gets(fbuf);
                        if (fbuf[0])
-                               kernel = fbuf;
+                               strcpy(kernel, fbuf);
                        else {
                                boothowto &= ~RB_ASKNAME;
                                i = 0;
-                               kernel = kernels[i];
+                               strcpy(kernel, kernels[i]);
                        }
                }
 
@@ -308,7 +311,7 @@
                 */
                if ((boothowto & RB_ASKNAME) == 0 &&
                    i != -1 && kernels[++i]) {
-                       kernel = kernels[i];
+                       strcpy(kernel, kernels[i]);
                        printf(": trying %s...\n", kernel);
                } else {
                        printf("\n");
diff -r b466feb9feaf -r 0e9e5c5e1a73 sys/arch/sparc/stand/common/promdev.c
--- a/sys/arch/sparc/stand/common/promdev.c     Wed Apr 27 07:48:02 2005 +0000
+++ b/sys/arch/sparc/stand/common/promdev.c     Wed Apr 27 07:59:47 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: promdev.c,v 1.15 2003/07/30 15:58:40 mrg Exp $ */
+/*     $NetBSD: promdev.c,v 1.16 2005/04/27 07:59:47 martin Exp $ */
 
 /*
  * Copyright (c) 1993 Paul Kranenburg
@@ -91,7 +91,7 @@
        { "obp v2", obp_v2_strategy, null_devopen, obp_close, null_devioctl };
 
 
-char   *prom_bootdevice;
+char   prom_bootdevice[MAX_PROM_PATH];
 static int     saveecho;
 
 
@@ -139,7 +139,7 @@
        case PROM_OBP_V2:
        case PROM_OBP_V3:
        case PROM_OPENFIRM:
-               if (prom_bootdevice == NULL) {
+               if (*prom_bootdevice == '\0') {
                        error = ENXIO;
                        break;
                }
diff -r b466feb9feaf -r 0e9e5c5e1a73 sys/arch/sparc/stand/common/promdev.h
--- a/sys/arch/sparc/stand/common/promdev.h     Wed Apr 27 07:48:02 2005 +0000
+++ b/sys/arch/sparc/stand/common/promdev.h     Wed Apr 27 07:59:47 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: promdev.h,v 1.9 2003/03/01 13:01:56 pk Exp $ */
+/*     $NetBSD: promdev.h,v 1.10 2005/04/27 07:59:47 martin Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -55,7 +55,10 @@
 #define DDB_MAGIC2     ( ('D'<<24) | ('D'<<16) | ('B'<<8) | ('2') )
 
 extern time_t  getsecs __P((void));
-extern char    *prom_bootdevice;
+
+#define        MAX_PROM_PATH   128
+
+extern char    prom_bootdevice[MAX_PROM_PATH];
 extern int     cputyp, nbpg, pgofset, pgshift;
 extern int     debug;
 



Home | Main Index | Thread Index | Old Index