From dada@freepass.tu-graz.ac.at  Mon Apr 14 03:36:12 1997
Received: from freepass.tu-graz.ac.at (freepass.tu-graz.ac.at [129.27.193.133])
          by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id DAA02260
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 14 Apr 1997 03:35:51 -0700 (PDT)
Received: (from dada@localhost) by freepass.tu-graz.ac.at (8.6.11/8.6.9) id MAA13786; Mon, 14 Apr 1997 12:32:23 +0200
Message-Id: <199704141032.MAA13786@freepass.tu-graz.ac.at>
Date: Mon, 14 Apr 1997 12:32:23 +0200
From: Martin Kammerhofer <dada@freepass.tu-graz.ac.at>
Reply-To: dada@sbox.tu-graz.ac.at
To: FreeBSD-gnats-submit@freebsd.org
Subject: missing error checking in mount_mfs(8) aka newfs
X-Send-Pr-Version: 3.2

>Number:         3286
>Category:       bin
>Synopsis:       [PATCH] missing error checking in mount_mfs(8) aka newfs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 14 03:40:19 PDT 1997
>Closed-Date:    Thu May 10 14:23:27 PDT 2001
>Last-Modified:  Sun Jul 15 02:40:00 PDT 2001
>Originator:     Martin Kammerhofer
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
Graz University of Technology
>Environment:

(nearly) stock 2.2.1 system

the following must be present in /etc/disktab:

minimum:ty=mfs:se#512:nt#1:rm#300:\
	:ns#2880:nc#1:\
	:pa#2880:oa#0:ba#4096:fa#512:\
	:pc#2880:oc#0:bc#4096:fc#512:

Actually any entry without a 'b'-partition (pb#) will do.

>Description:

Actually it's 2 bugs in one report. I marked them A) and B)

A) By using mount_mfs with option -T one experiences strange behaviour:
1. the command failes
2. there is no warning or error message printed

B) Option -N (dont't do but report what would be done) doesn't work
	for mount_mfs.

Even with option -N mount_mfs performs the mount and reports nothing.

>How-To-Repeat:

Don't worry if you have no /dev/dummy :)

A)
mkdir /ram
mount_mfs -T minimum /dev/dummy /ram
df -i /ram

It's not mounted where it should.

What happened?
Since there was no size (-s) on the command line the size of partition 'b'
from the disktab-entry 'minimum' was taken, unfortunately it's zero (undefined).
This caused code in mkfs.c to fail, but no error is printed.

The man page doesn't say that partition 'b' is used, only that a disklabel
is read.

B)
mount_mfs -N -T fd1440 -c 2 -i 5000 /dev/dummy /ram
df -i /ram

It's mounted where it shouldn't, nothing is printed where it should.

>Fix:
--- /src/sbin/newfs/mkfs.c	Fri Sep 20 06:23:09 1996
+++ ./mkfs.c	Sat Apr 12 19:56:44 1997
@@ -190,8 +190,10 @@
 		} else {
 			if (fssize * sectorsize > memleft)
 				fssize = (memleft - 16384) / sectorsize;
-			if ((membase = malloc(fssize * sectorsize)) == 0)
+			if ((membase = malloc(fssize * sectorsize)) == 0) {
+				fprintf(stderr, "mkfs's malloc failed\n");
 				exit(12);
+			}
 		}
 	}
 	fsi = fi;
@@ -606,7 +608,7 @@
 	/*
 	 * Dump out summary information about file system.
 	 */
-	if (!mfs) {
+	if (!mfs || Nflag) {
 		printf("%s:\t%d sectors in %d %s of %d tracks, %d sectors\n",
 		    fsys, sblock.fs_size * NSPF(&sblock), sblock.fs_ncyl,
 		    "cylinders", sblock.fs_ntrak, sblock.fs_nsect);
@@ -622,13 +624,13 @@
 	 * Now build the cylinders group blocks and
 	 * then print out indices of cylinder groups.
 	 */
-	if (!mfs)
+	if (!mfs || Nflag)
 		printf("super-block backups (for fsck -b #) at:\n");
 	i = 0;
 	width = charsperline();
 	for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
 		initcg(cylno, utime);
-		if (mfs)
+		if (mfs && !Nflag)
 			continue;
 		j = sprintf(tmpbuf, " %d,",
 			fsbtodb(&sblock, cgsblock(&sblock, cylno)));
@@ -640,9 +642,9 @@
 		printf("%s", tmpbuf);
 		fflush(stdout);
 	}
-	if (!mfs)
+	if (!mfs || Nflag)
 		printf("\n");
-	if (Nflag && !mfs)
+	if (Nflag)
 		exit(0);
 	/*
 	 * Now construct the initial file system,
@@ -908,6 +910,8 @@
 	node.di_nlink = 2;
 	node.di_size = sblock.fs_bsize;
 	node.di_db[0] = alloc(node.di_size, node.di_mode);
+	if (node.di_db[0] == 0)
+		exit(38);	/* alloc failed */
 	node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
 	wtfs(fsbtodb(&sblock, node.di_db[0]), node.di_size, buf);
 	iput(&node, LOSTFOUNDINO);
@@ -925,6 +929,8 @@
 	else
 		node.di_size = makedir(root_dir, PREDEFDIR);
 	node.di_db[0] = alloc(sblock.fs_fsize, node.di_mode);
+	if (node.di_db[0] == 0)
+		exit(39);	/* alloc failed */
 	node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
 	wtfs(fsbtodb(&sblock, node.di_db[0]), sblock.fs_fsize, buf);
 	iput(&node, ROOTINO);

--- /src/sbin/newfs/newfs.c	Mon Jan  1 09:37:28 1996
+++ ./newfs.c	Sat Apr 12 17:02:16 1997
@@ -215,7 +215,7 @@
 	struct partition oldpartition;
 	struct stat st;
 	struct statfs *mp;
-	int fsi, fso, len, n;
+	int fsi = -1, fso, len, n;
 	char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
 #ifdef MFS
 	struct vfsconf *vfc;
@@ -228,7 +228,6 @@
 
 	if (strstr(progname, "mfs")) {
 		mfs = 1;
-		Nflag++;
 	}
 
 	opstring = mfs ?
@@ -365,7 +364,7 @@
 			(void)sprintf(device, "%s%s", _PATH_DEV, special);
 		special = device;
 	}
-	if (Nflag) {
+	if (Nflag || mfs) {
 		fso = -1;
 	} else {
 		fso = open(special, O_WRONLY);
@@ -399,6 +398,8 @@
 		if (lp == NULL)
 			fatal("%s: unknown disk type", disktype);
 		pp = &lp->d_partitions[1];
+		if (pp->p_size == 0)
+			fatal("%s: partition `b' undefined", disktype);
 	} else {
 		fsi = open(special, O_RDONLY);
 		if (fsi < 0)
@@ -538,7 +539,8 @@
 #endif
 	if (!Nflag)
 		close(fso);
-	close(fsi);
+	if (fsi >= 0)
+		close(fsi);
 #ifdef MFS
 	if (mfs) {
 		struct mfs_args args;
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: johan 
State-Changed-When: Thu May 10 14:23:27 PDT 2001 
State-Changed-Why:  
When trying to repeat this on a 4.3-RC I get: 
numeri# mount_mfs -T minimum /dev/dummy /ram 
preposterous size 0 
numeri# mount_mfs -N -T fd1440 -c 2 -i 5000 /dev/dummy /ram 
numeri# df -i /ram 
Filesystem  1K-blocks     Used    Avail Capacity iused   ifree  %iused  Mounted on 
mfs:30968        1371        0     1261     0%       1     317     0%   /ram 

I guess this has been fixed since the 2.2.1 days. 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=3286 

From: Martin Kammerhofer <mkamm@sbox.tu-graz.ac.at>
To: freebsd-gnats-submit@FreeBSD.org, dada@sbox.tu-graz.ac.at
Cc:  
Subject: Re: bin/3286: [PATCH] missing error checking in mount_mfs(8) aka
 newfs
Date: Sat, 14 Jul 2001 19:25:00 +0200 (CEST)

 Actually only problem A has been fixed in 4.3-stable. Problem B is still
 present. Option -N still does not inhibit the actual mount taking place
 for MFS filesystems.
 However since MFS is being replaced by MD (already done in -current) I
 agree with having this PR closed.
 
>Unformatted:
