Date: Mon, 14 Apr 1997 12:32:23 +0200 From: Martin Kammerhofer <dada@freepass.tu-graz.ac.at> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/3286: missing error checking in mount_mfs(8) aka newfs Message-ID: <199704141032.MAA13786@freepass.tu-graz.ac.at> Resent-Message-ID: <199704141040.DAA02661@freefall.freebsd.org>
index | next in thread | raw e-mail
>Number: 3286
>Category: bin
>Synopsis: missing error checking in mount_mfs(8) aka newfs
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Apr 14 03:40:19 PDT 1997
>Last-Modified:
>Originator: Martin Kammerhofer
>Organization:
Graz University of Technology
>Release: FreeBSD 2.2.1-RELEASE i386
>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;
>Audit-Trail:
>Unformatted:
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704141032.MAA13786>
