From 8a978495e7c0717a3cc6b8c49e445fa403aa9c7f Mon Sep 17 00:00:00 2001 From: David Greenman Date: Wed, 15 Feb 1995 14:20:50 +0000 Subject: [PATCH] Verify that the last component of the mount point path exists and is a directory - allows for better error reporting. --- sbin/mount/mount.c | 12 +++++++++++- sbin/mount_ifs/mount.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index ee05e9db3367..691c07a473db 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94"; #include #include #include +#include +#include #include #include @@ -245,6 +247,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts) const char *vfstype, *spec, *name, *options, *mntopts; int flags; { + struct stat sb; + /* List of directories containing mount_xxx subcommands. */ static const char *edirs[] = { _PATH_SBIN, @@ -257,10 +261,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts) int argc, i, status; char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN]; - if (realpath(name, mntpath) == NULL) { + if ((realpath(name, mntpath) != NULL) && (stat(mntpath, &sb) == NULL)) { + if ((sb.st_mode & S_IFDIR) == 0) { + warnx("%s: Not a directory", mntpath); + return (1); + } + } else { warn("%s", mntpath); return (1); } + if (mntopts == NULL) mntopts = ""; diff --git a/sbin/mount_ifs/mount.c b/sbin/mount_ifs/mount.c index ee05e9db3367..691c07a473db 100644 --- a/sbin/mount_ifs/mount.c +++ b/sbin/mount_ifs/mount.c @@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94"; #include #include #include +#include +#include #include #include @@ -245,6 +247,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts) const char *vfstype, *spec, *name, *options, *mntopts; int flags; { + struct stat sb; + /* List of directories containing mount_xxx subcommands. */ static const char *edirs[] = { _PATH_SBIN, @@ -257,10 +261,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts) int argc, i, status; char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN]; - if (realpath(name, mntpath) == NULL) { + if ((realpath(name, mntpath) != NULL) && (stat(mntpath, &sb) == NULL)) { + if ((sb.st_mode & S_IFDIR) == 0) { + warnx("%s: Not a directory", mntpath); + return (1); + } + } else { warn("%s", mntpath); return (1); } + if (mntopts == NULL) mntopts = "";