@@ -40,7 +40,7 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar
4040 mode_t mode = static_cast <int >(arg2);
4141 START_LOG (tid, " call(path=%s, flags=%d, mode=%d)" , pathname.data (), flags, mode);
4242
43- if (is_forbidden_path (pathname)) {
43+ if (! is_capio_path (pathname)) {
4444 LOG (" Path %s is forbidden: skip" , pathname.data ());
4545 return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
4646 }
@@ -52,7 +52,12 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar
5252 LOG (" Create request sent" );
5353 }
5454
55- int fd = static_cast <int >(syscall_no_intercept (SYS_creat, arg0, arg1, arg2, arg3, arg4, arg5));
55+ const int fd =
56+ static_cast <int >(syscall_no_intercept (SYS_creat, arg0, arg1, arg2, arg3, arg4, arg5));
57+
58+ if (fd < 0 ) {
59+ return CAPIO_POSIX_SYSCALL_ERRNO;
60+ }
5661
5762 LOG (" fd=%d" , fd);
5863
@@ -61,8 +66,7 @@ int creat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar
6166 add_capio_fd (tid, path, fd, 0 , (flags & O_CLOEXEC) == O_CLOEXEC);
6267 }
6368
64- *result = fd;
65- return CAPIO_POSIX_SYSCALL_SUCCESS;
69+ return posix_return_value (fd, result);
6670}
6771#endif // SYS_creat
6872
@@ -76,7 +80,7 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
7680
7781 std::string path = compute_abs_path (pathname.data (), -1 );
7882
79- if (is_forbidden_path (pathname) || !is_capio_path (path )) {
83+ if (!is_capio_path (pathname )) {
8084 LOG (" Path %s is not a capio path: skip" , pathname.data ());
8185 return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
8286 }
@@ -95,13 +99,15 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
9599
96100 const int fd =
97101 static_cast <int >(syscall_no_intercept (SYS_open, arg0, arg1, arg2, arg3, arg4, arg5));
102+ if (fd < 0 ) {
103+ return CAPIO_POSIX_SYSCALL_ERRNO;
104+ }
98105
99106 LOG (" Adding capio path" );
100107 add_capio_fd (tid, resolved_path, fd, 0 , (flags & O_CLOEXEC) == O_CLOEXEC);
101108 LOG (" fd=%d" , fd);
102109
103- *result = fd;
104- return CAPIO_POSIX_SYSCALL_SUCCESS;
110+ return posix_return_value (fd, result);
105111}
106112#endif // SYS_open
107113
@@ -116,7 +122,7 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
116122 mode);
117123
118124 std::string path = compute_abs_path (pathname.data (), dirfd);
119- if (is_forbidden_path (pathname) || !is_capio_path (path )) {
125+ if (!is_capio_path (pathname )) {
120126 LOG (" Path %s is not a capio path: skip" , pathname.data ());
121127 return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
122128 }
@@ -138,11 +144,14 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
138144 static_cast <int >(syscall_no_intercept (SYS_openat, arg0, arg1, arg2, arg3, arg4, arg5));
139145 LOG (" fd=%d" , fd);
140146
147+ if (fd < 0 ) {
148+ return CAPIO_POSIX_SYSCALL_ERRNO;
149+ }
150+
141151 LOG (" Adding resolved capio path (%s)" , resolved_path.c_str ());
142152 add_capio_fd (tid, resolved_path, fd, 0 , (flags & O_CLOEXEC) == O_CLOEXEC);
143153
144- *result = fd;
145- return CAPIO_POSIX_SYSCALL_SUCCESS;
154+ return posix_return_value (fd, result);
146155}
147156#endif // SYS_openat
148157
0 commit comments