Module Name:    src
Committed By:   christos
Date:           Thu Jan  5 19:43:59 UTC 2012

Modified Files:
        src/distrib/utils/sysinst: defs.h disks.c label.c savenewlabel.c

Log Message:
- avoid dereferencing junk if fstype is out of bounds.
- kill mountnames since it is not used.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/distrib/utils/sysinst/defs.h
cvs rdiff -u -r1.117 -r1.118 src/distrib/utils/sysinst/disks.c
cvs rdiff -u -r1.57 -r1.58 src/distrib/utils/sysinst/label.c
cvs rdiff -u -r1.7 -r1.8 src/distrib/utils/sysinst/savenewlabel.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/utils/sysinst/defs.h
diff -u src/distrib/utils/sysinst/defs.h:1.155 src/distrib/utils/sysinst/defs.h:1.156
--- src/distrib/utils/sysinst/defs.h:1.155	Fri Nov  4 07:27:00 2011
+++ src/distrib/utils/sysinst/defs.h	Thu Jan  5 14:43:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.155 2011/11/04 11:27:00 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.156 2012/01/05 19:43:59 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -40,8 +40,7 @@
 /* System includes needed for this. */
 #include <sys/types.h>
 #include <sys/disklabel.h>
-extern const char * const fstypenames[];
-extern const char * const mountnames[];
+const char *getfstypename(char *, size_t, uint8_t);
 
 static inline void *
 deconst(const void *p)

Index: src/distrib/utils/sysinst/disks.c
diff -u src/distrib/utils/sysinst/disks.c:1.117 src/distrib/utils/sysinst/disks.c:1.118
--- src/distrib/utils/sysinst/disks.c:1.117	Fri Nov  4 07:27:00 2011
+++ src/distrib/utils/sysinst/disks.c	Thu Jan  5 14:43:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.117 2011/11/04 11:27:00 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.118 2012/01/05 19:43:59 christos Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -47,10 +47,7 @@
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #define FSTYPENAMES
-#define MOUNTNAMES
-#define static
 #include <sys/disklabel.h>
-#undef static
 
 #include <dev/scsipi/scsipi_all.h>
 #include <sys/scsiio.h>
@@ -91,6 +88,18 @@ static void fixsb(const char *, const ch
 
 static const char *disk_names[] = { DISK_NAMES, "vnd", NULL };
 
+const char *
+getfstypename(char *buf, size_t len, uint8_t fstype)
+{
+	
+	if (fstype >= __arraycount(fstypenames) ||
+	    fstypenames[fstype] == NULL)
+		snprintf(buf, len, "*unknown*%" PRIu8 "*", fstype);
+	else
+		strlcpy(buf, fstypenames[fstype], len);
+	return buf;
+}
+
 /* from src/sbin/atactl/atactl.c
  * extract_string: copy a block of bytes out of ataparams and make
  * a proper string out of it, truncating trailing spaces and preserving
@@ -438,6 +447,7 @@ fmt_fspart(menudesc *m, int ptn, void *a
 {
 	unsigned int poffset, psize, pend;
 	const char *desc;
+	char buf[128];
 	static const char *Yes, *No;
 	partinfo *p = bsdlabel + ptn;
 
@@ -459,7 +469,7 @@ fmt_fspart(menudesc *m, int ptn, void *a
 		else
 			desc = "FFSv1";
 	else
-		desc = fstypenames[p->pi_fstype];
+		desc = getfstypename(buf, sizeof(buf), p->pi_fstype);
 
 #ifdef PART_BOOT
 	if (ptn == PART_BOOT)

Index: src/distrib/utils/sysinst/label.c
diff -u src/distrib/utils/sysinst/label.c:1.57 src/distrib/utils/sysinst/label.c:1.58
--- src/distrib/utils/sysinst/label.c:1.57	Tue Jul  5 21:20:03 2011
+++ src/distrib/utils/sysinst/label.c	Thu Jan  5 14:43:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: label.c,v 1.57 2011/07/06 01:20:03 mrg Exp $	*/
+/*	$NetBSD: label.c,v 1.58 2012/01/05 19:43:59 christos Exp $	*/
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: label.c,v 1.57 2011/07/06 01:20:03 mrg Exp $");
+__RCSID("$NetBSD: label.c,v 1.58 2012/01/05 19:43:59 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -387,7 +387,9 @@ edit_ptn(menudesc *menu, void *arg)
 
 	if (all_fstype_menu == -1) {
 		for (i = 0; i < nelem(all_fstypes); i++) {
-			all_fstypes[i].opt_name = fstypenames[i];
+			char buf[128];
+			all_fstypes[i].opt_name = strdup(getfstypename(buf,
+			    sizeof(buf), i));
 			all_fstypes[i].opt_menu = OPT_NOMENU;
 			all_fstypes[i].opt_flags = 0;
 			all_fstypes[i].opt_action = set_fstype;
@@ -472,6 +474,7 @@ set_ptn_label(menudesc *m, int opt, void
 {
 	partinfo *p = arg;
 	const char *c;
+	char buf[128];
 
 	if (m->opts[opt].opt_flags & OPT_IGNORE
 	    && (opt != PTN_MENU_END || p->pi_fstype == FS_UNUSED)) {
@@ -487,7 +490,7 @@ set_ptn_label(menudesc *m, int opt, void
 			else
 				c = "FFSv1";
 		else
-			c = fstypenames[p->pi_fstype];
+			c = getfstypename(buf, sizeof(buf), p->pi_fstype);
 		wprintw(m->mw, msg_string(MSG_fstype_fmt), c);
 		break;
 	case PTN_MENU_START:

Index: src/distrib/utils/sysinst/savenewlabel.c
diff -u src/distrib/utils/sysinst/savenewlabel.c:1.7 src/distrib/utils/sysinst/savenewlabel.c:1.8
--- src/distrib/utils/sysinst/savenewlabel.c:1.7	Sun Sep 20 18:43:00 2009
+++ src/distrib/utils/sysinst/savenewlabel.c	Thu Jan  5 14:43:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: savenewlabel.c,v 1.7 2009/09/20 22:43:00 abs Exp $	*/
+/*	$NetBSD: savenewlabel.c,v 1.8 2012/01/05 19:43:59 christos Exp $	*/
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: savenewlabel.c,v 1.7 2009/09/20 22:43:00 abs Exp $");
+__RCSID("$NetBSD: savenewlabel.c,v 1.8 2012/01/05 19:43:59 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -86,14 +86,19 @@ savenewlabel(partinfo *lp, int nparts)
 	    (uint32_t)dlsize);
 	scripting_fprintf(f, "\t:se#%d:%s\\\n", sectorsize, doessf);
 	for (i = 0; i < nparts; i++) {
-		scripting_fprintf(f, "\t:p%c#%" PRIu32 ":o%c#%" PRIu32 ":t%c=%s:",
-		    'a'+i, (uint32_t)bsdlabel[i].pi_size,
-		    'a'+i, (uint32_t)bsdlabel[i].pi_offset,
-		    'a'+i, fstypenames[bsdlabel[i].pi_fstype]);
+		char fstypename[128];
+
+		scripting_fprintf(f, "\t:p%c#%" PRIu32 ":o%c#%" PRIu32
+		    ":t%c=%s:", 'a'+i, (uint32_t)bsdlabel[i].pi_size,
+		    'a'+i, (uint32_t)bsdlabel[i].pi_offset, 'a'+i,
+		    getfstypename(fstypename, sizeof(fstypename),
+		    bsdlabel[i].pi_fstype));
 		if (PI_ISBSDFS(&bsdlabel[i]))
-			scripting_fprintf (f, "b%c#%" PRIu32 ":f%c#%" PRIu32 ":ta=4.2BSD:",
-			   'a'+i, (uint32_t)(bsdlabel[i].pi_fsize * bsdlabel[i].pi_frag),
-			   'a'+i, (uint32_t)bsdlabel[i].pi_fsize);
+			scripting_fprintf (f, "b%c#%" PRIu32 ":f%c#%" PRIu32
+			    ":ta=4.2BSD:", 'a'+i,
+			    (uint32_t)(bsdlabel[i].pi_fsize *
+			    bsdlabel[i].pi_frag),
+			    'a'+i, (uint32_t)bsdlabel[i].pi_fsize);
 	
 		if (i < nparts - 1)
 			scripting_fprintf(f, "\\\n");

Reply via email to