Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162151541
D55379.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D55379.diff
View Options
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -169,11 +169,9 @@
{
struct cb_file *cf;
struct stat sb;
- int fd, flags;
+ int fd;
cf = NULL;
- fd = -1;
- flags = O_RDONLY | O_RESOLVE_BENEATH;
if (hostbase_fd == -1)
return (ENOENT);
@@ -185,20 +183,21 @@
if (filename[0] == '\0')
filename = ".";
- if (fstatat(hostbase_fd, filename, &sb, AT_RESOLVE_BENEATH) < 0)
- return (errno);
-
- if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode))
- return (EINVAL);
-
- if (S_ISDIR(sb.st_mode))
- flags |= O_DIRECTORY;
-
/* May be opening the root dir */
- fd = openat(hostbase_fd, filename, flags);
+ fd = openat(hostbase_fd, filename, O_RDONLY | O_RESOLVE_BENEATH);
if (fd < 0)
return (errno);
+ if (fstat(fd, &sb) < 0) {
+ int serrno = errno;
+
+ close(fd);
+ return (serrno);
+ } else if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode)) {
+ close(fd);
+ return (EINVAL);
+ }
+
cf = malloc(sizeof(struct cb_file));
if (cf == NULL) {
close(fd);
@@ -217,7 +216,6 @@
return (ENOMEM);
}
} else {
- assert(S_ISREG(cf->cf_stat.st_mode));
cf->cf_isdir = 0;
cf->cf_u.fd = fd;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jul 11, 8:23 AM (2 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34954253
Default Alt Text
D55379.diff (1 KB)
Attached To
Mode
D55379: bhyveload: simplify cb_open() and eliminate minor TOCTOU
Attached
Detach File
Event Timeline
Log In to Comment