Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Sanitize disk type and packname a bit more ...



details:   https://anonhg.NetBSD.org/src/rev/4c6d2c303f02
branches:  trunk
changeset: 847002:4c6d2c303f02
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Dec 06 19:36:22 2019 +0000

description:
Sanitize disk type and packname a bit more - when using existing disklabel
partitions we might run into trouble later when filing this label (unescaped)
in disktab format otherwise.

diffstat:

 usr.sbin/sysinst/disklabel.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r 1d11861aab52 -r 4c6d2c303f02 usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Fri Dec 06 19:36:21 2019 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Fri Dec 06 19:36:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.15 2019/11/12 16:33:14 martin Exp $    */
+/*     $NetBSD: disklabel.c,v 1.16 2019/12/06 19:36:22 martin Exp $    */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -281,13 +281,10 @@
        assert(parts->l.d_ncylinders != 0);
        assert(parts->l.d_secpercyl != 0);
 
-       sprintf(fname, "/tmp/disklabel.%u", getpid());
-       f = fopen(fname, "w");
-       if (f == NULL)
-               return false;
-
        /* make sure we have a 0 terminated packname */
        strlcpy(packname, parts->l.d_packname, sizeof packname);
+       if (packname[0] == 0)
+               strcpy(packname, "fictious");
 
        /* fill typename with disk name prefix, if not already set */
        if (strlen(parts->l.d_typename) == 0) {
@@ -299,6 +296,12 @@
                }
        }
        parts->l.d_typename[sizeof(parts->l.d_typename)-1] = 0;
+       for (d = parts->l.d_typename; *d; d++) {
+               if (isalnum((unsigned char)*d) || *d == '-')
+                       continue;
+               *d = 0;
+               break;
+       }
 
        /* we need a valid disk type name, so enforce an arbitrary if
         * above did not yield a usable one */
@@ -306,6 +309,11 @@
                strncpy(parts->l.d_typename, "SCSI",
                    sizeof(parts->l.d_typename));
 
+       sprintf(fname, "/tmp/disklabel.%u", getpid());
+       f = fopen(fname, "w");
+       if (f == NULL)
+               return false;
+
        lp = parts->l.d_partitions;
        scripting_fprintf(NULL, "cat <<EOF >%s\n", fname);
        scripting_fprintf(f, "%s|NetBSD installation generated:\\\n",



Home | Main Index | Thread Index | Old Index