Module Name: src
Committed By: martin
Date: Fri Dec 6 19:36:22 UTC 2019
Modified Files:
src/usr.sbin/sysinst: disklabel.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/sysinst/disklabel.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/sysinst/disklabel.c
diff -u src/usr.sbin/sysinst/disklabel.c:1.15 src/usr.sbin/sysinst/disklabel.c:1.16
--- src/usr.sbin/sysinst/disklabel.c:1.15 Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/disklabel.c Fri Dec 6 19:36:22 2019
@@ -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 @@ disklabel_write_to_disk(struct disk_part
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 @@ disklabel_write_to_disk(struct disk_part
}
}
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 @@ disklabel_write_to_disk(struct disk_part
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",