Source-Changes-HG archive

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

[src/netbsd-9]: src/usr.sbin/sysinst Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/dca08b269872
branches:  netbsd-9
changeset: 466046:dca08b269872
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Dec 09 19:31:18 2019 +0000

description:
Pull up following revision(s) (requested by martin in ticket #537):
        usr.sbin/sysinst/disklabel.c: revision 1.16
        usr.sbin/sysinst/disklabel.c: revision 1.17
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.
Relax restrictions on packnames, as disklabel(8) does not do full decoding
for the tag field.
Fix quoting of command args.

diffstat:

 usr.sbin/sysinst/disklabel.c |  44 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 11 deletions(-)

diffs (97 lines):

diff -r dba32765aac3 -r dca08b269872 usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Mon Dec 09 16:23:19 2019 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Mon Dec 09 19:31:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.10.2.5 2019/11/17 13:45:26 msaitoh Exp $       */
+/*     $NetBSD: disklabel.c,v 1.10.2.6 2019/12/09 19:31:18 bouyer Exp $        */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -262,13 +262,32 @@
        return &parts->dp;
 }
 
+/*
+ * Escape a string for usage as a tag name in a capfile(5),
+ * we really know there is enough space in the destination buffer...
+ */
+static void
+escape_capfile(char *dest, const char *src, size_t len)
+{
+       while (*src && len > 0) {
+               if (*src == ':')
+                       *dest++ = ' ';
+               else
+                       *dest++ = *src;
+               src++;
+               len--;
+       }
+       *dest = 0;
+}
+
 static bool
 disklabel_write_to_disk(struct disk_partitions *arg)
 {
        struct disklabel_disk_partitions *parts =
            (struct disklabel_disk_partitions*)arg;
        FILE *f;
-       char fname[PATH_MAX], packname[sizeof(parts->l.d_packname)+1];
+       char fname[PATH_MAX], packname[sizeof(parts->l.d_packname)+1],
+           disktype[sizeof(parts->l.d_typename)+1];
        int i, rv = 0;
        const char *disk = parts->dp.disk, *s;
        const struct partition *lp;
@@ -281,13 +300,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) {
@@ -298,18 +314,24 @@
                        *d = *s;
                }
        }
-       parts->l.d_typename[sizeof(parts->l.d_typename)-1] = 0;
 
        /* we need a valid disk type name, so enforce an arbitrary if
         * above did not yield a usable one */
        if (strlen(parts->l.d_typename) == 0)
                strncpy(parts->l.d_typename, "SCSI",
                    sizeof(parts->l.d_typename));
+       escape_capfile(disktype, parts->l.d_typename,
+           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",
-           parts->l.d_typename);
+           disktype);
        scripting_fprintf(f, "\t:nc#%d:nt#%d:ns#%d:\\\n",
            parts->l.d_ncylinders, parts->l.d_ntracks, parts->l.d_nsectors);
        scripting_fprintf(f, "\t:sc#%d:su#%" PRIu32 ":\\\n",
@@ -351,8 +373,8 @@
         */
 #ifdef DISKLABEL_CMD
        /* disklabel the disk */
-       rv = run_program(RUN_DISPLAY, "%s -f %s %s %s %s",
-           DISKLABEL_CMD, fname, disk, parts->l.d_typename, packname);
+       rv = run_program(RUN_DISPLAY, "%s -f %s %s '%s' '%s'",
+           DISKLABEL_CMD, fname, disk, disktype, packname);
 #endif
 
        unlink(fname);



Home | Main Index | Thread Index | Old Index