Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150202522
D17963.id50338.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
D17963.id50338.diff
View Options
Index: lib/libnv/common_impl.h
===================================================================
--- lib/libnv/common_impl.h
+++ lib/libnv/common_impl.h
@@ -34,6 +34,7 @@
#ifndef _COMMON_IMPL_H_
#define _COMMON_IMPL_H_
-#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF)
+/* dup2(2) does not require any capability rights. */
+#define fd_is_valid(fd) (dup2((fd), (fd)) != -1 || errno != EBADF)
#endif /* !_COMMON_IMPL_H_ */
Index: lib/libnv/msgio.c
===================================================================
--- lib/libnv/msgio.c
+++ lib/libnv/msgio.c
@@ -66,11 +66,6 @@
PJDLOG_ASSERT(fd >= 0);
- if (!fd_is_valid(fd)) {
- errno = EBADF;
- return (-1);
- }
-
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
Index: lib/libnv/tests/nvlist_send_recv_test.c
===================================================================
--- lib/libnv/tests/nvlist_send_recv_test.c
+++ lib/libnv/tests/nvlist_send_recv_test.c
@@ -306,15 +306,12 @@
CHECK(name == NULL);
}
-int
-main(void)
+static void
+send_nvlist(void)
{
int status, socks[2];
pid_t pid;
- printf("1..134\n");
- fflush(stdout);
-
if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0)
err(1, "socketpair() failed");
pid = fork();
@@ -326,7 +323,7 @@
/* Child. */
close(socks[0]);
child(socks[1]);
- return (0);
+ _exit(0);
default:
/* Parent. */
close(socks[1]);
@@ -336,6 +333,35 @@
if (waitpid(pid, &status, 0) < 0)
err(1, "waitpid() failed");
+}
+
+static void
+send_closed_fd(void)
+{
+ nvlist_t *nvl;
+ int error, socks[2];
+
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0)
+ err(1, "socketpair() failed");
+
+ nvl = nvlist_create(0);
+ nvlist_add_descriptor(nvl, "fd", 12345);
+ error = nvlist_error(nvl);
+ CHECK(error == EBADF);
+
+ error = nvlist_send(socks[1], nvl);
+ CHECK(error != 0 && errno == EBADF);
+}
+
+int
+main(void)
+{
+
+ printf("1..136\n");
+ fflush(stdout);
+
+ send_nvlist();
+ send_closed_fd();
return (0);
}
Index: sys/contrib/libnv/nvpair.c
===================================================================
--- sys/contrib/libnv/nvpair.c
+++ sys/contrib/libnv/nvpair.c
@@ -1276,11 +1276,6 @@
{
nvpair_t *nvp;
- if (value < 0 || !fd_is_valid(value)) {
- ERRNO_SET(EBADF);
- return (NULL);
- }
-
value = fcntl(value, F_DUPFD_CLOEXEC, 0);
if (value < 0)
return (NULL);
@@ -1517,11 +1512,6 @@
if (value[ii] == -1) {
fds[ii] = -1;
} else {
- if (!fd_is_valid(value[ii])) {
- ERRNO_SET(EBADF);
- goto fail;
- }
-
fds[ii] = fcntl(value[ii], F_DUPFD_CLOEXEC, 0);
if (fds[ii] == -1)
goto fail;
@@ -2035,10 +2025,6 @@
NVPAIR_ASSERT(nvp);
PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR_ARRAY);
- if (value < 0 || !fd_is_valid(value)) {
- ERRNO_SET(EBADF);
- return -1;
- }
fd = fcntl(value, F_DUPFD_CLOEXEC, 0);
if (fd == -1) {
return (-1);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 31, 5:55 AM (3 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30622859
Default Alt Text
D17963.id50338.diff (2 KB)
Attached To
Mode
D17963: Redefine fd_is_valid() to work with kern.trap_enotcap=1.
Attached
Detach File
Event Timeline
Log In to Comment