Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164866140
D55379.id172256.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.id172256.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
Wed, Aug 5, 9:14 AM (31 m, 36 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35951723
Default Alt Text
D55379.id172256.diff (1 KB)
Attached To
Mode
D55379: bhyveload: simplify cb_open() and eliminate minor TOCTOU
Attached
Detach File
Event Timeline
Log In to Comment