mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-16 15:44:04 +01:00
Verify that the last component of the mount point path exists and is
a directory - allows for better error reporting.
This commit is contained in:
parent
b019cc8f8e
commit
8a978495e7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=6441
@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
@ -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 = "";
|
||||
|
||||
|
@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
@ -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 = "";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user