Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164595825
D53185.id164486.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D53185.id164486.diff
View Options
Index: lib/libutil/mntopts.c
===================================================================
--- lib/libutil/mntopts.c
+++ lib/libutil/mntopts.c
@@ -145,6 +145,19 @@
return (0);
}
+static char *
+prependdevtopath(const char *path)
+{
+ static char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
+ u_long len;
+
+ if ((len = strlen(_PATH_DEV) + strlen(path) + 1) > sizeof(device))
+ return NULL;
+ strncpy(device, _PATH_DEV, len);
+ strncat(device, path, len - sizeof(_PATH_DEV));
+ return (device);
+}
+
/*
* Get the mount point information for name. Name may be mount point name
* or device name (with or without /dev/ preprended).
@@ -153,19 +166,19 @@
getmntpoint(const char *name)
{
struct stat devstat, mntdevstat;
- char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
- char *ddevname;
+ char *devname;
struct statfs *mntbuf, *statfsp;
- int i, mntsize, isdev;
- u_long len;
+ int i, len, isdev, mntsize, mntfromnamesize;
- if (stat(name, &devstat) != 0)
- return (NULL);
+ if (stat(name, &devstat) != 0 &&
+ (name[0] != '/' && stat(prependdevtopath(name), &devstat) != 0))
+ return (NULL);
if (S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode))
isdev = 1;
else
isdev = 0;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
+ mntfromnamesize = sizeof(statfsp->f_mntfromname);
for (i = 0; i < mntsize; i++) {
statfsp = &mntbuf[i];
if (isdev == 0) {
@@ -173,19 +186,21 @@
continue;
return (statfsp);
}
- ddevname = statfsp->f_mntfromname;
- if (*ddevname != '/') {
- if ((len = strlen(_PATH_DEV) + strlen(ddevname) + 1) >
- sizeof(statfsp->f_mntfromname) ||
- len > sizeof(device))
+ devname = statfsp->f_mntfromname;
+ if (*devname == '/') {
+ if (stat(devname, &mntdevstat) != 0)
+ continue;
+ } else {
+ devname = prependdevtopath(devname);
+ if (devname == NULL ||
+ (len = strlen(devname)) > mntfromnamesize)
continue;
- strncpy(device, _PATH_DEV, len);
- strncat(device, ddevname, len);
- if (stat(device, &mntdevstat) == 0)
- strncpy(statfsp->f_mntfromname, device, len);
+ if (stat(devname, &mntdevstat) != 0)
+ continue;
+ else
+ strncpy(statfsp->f_mntfromname, devname, len);
}
- if (stat(ddevname, &mntdevstat) == 0 &&
- S_ISCHR(mntdevstat.st_mode) &&
+ if (S_ISCHR(mntdevstat.st_mode) &&
mntdevstat.st_rdev == devstat.st_rdev)
return (statfsp);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 3, 6:27 AM (8 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35903547
Default Alt Text
D53185.id164486.diff (2 KB)
Attached To
Mode
D53185: Fix getmntpoint(3) to operate as it is documented in its manual page.
Attached
Detach File
Event Timeline
Log In to Comment