verify_syscalls: handle openat()
This fixes an issue where the C library called the openat syscall. This
was ignored and verify_syscalls would incorrectly fail.
Fixes
@@ -209,24 +209,17 @@ static void handle_write()
}
}
-static void handle_open()
+static void handle_open_common(long open_rc, const char *path)
{
- // fd = sys_open(const char *filename, int flags, int mode)
- long params[3];
- long rc = get_syscall_params(3, params);
-
- char path[PATH_MAX];
- get_syscall_str(params[0], path, sizeof(path));
-
- if (rc >= 0) {
- // Check if the process successfully opened the file of interest.
- // (match on suffix)
+ // Did the call to open succeed?
+ if (open_rc >= 0) {
+ // Is this the file of interest (match on suffix)?
size_t check_pathname_len = strlen(check_pathname);
size_t path_len = strlen(path);
if (path_len >= check_pathname_len &&
strstr(path + path_len - check_pathname_len, check_pathname) != 0) {
- //fprintf(stderr, "open(\"%s\") -> %ld\n", path, rc);
- check_fd = rc;
+ //fprintf(stderr, "open(\"%s\") -> %ld\n", path, open_rc);
+ check_fd = open_rc;
check_offset = 0;
open_call_count++;
@@ -236,6 +229,30 @@ static void handle_open()
}
}
+static void handle_open()
+{
+ // fd = sys_open(const char *filename, int flags, int mode)
+ long params[3];
+ long rc = get_syscall_params(3, params);
+
+ char path[PATH_MAX];
+ get_syscall_str(params[0], path, sizeof(path));
+
+ handle_open_common(rc, path);
+}
+
+static void handle_openat()
+{
+ // fd = sys_openat(int dirfd, const char *filename, int flags, int mode)
+ long params[4];
+ long rc = get_syscall_params(4, params);
+
+ char path[PATH_MAX];
+ get_syscall_str(params[1], path, sizeof(path));
+
+ handle_open_common(rc, path);
+}
+
static void handle_close()
{
// sys_close(int flags)
@@ -374,6 +391,12 @@ int main(int argc, char *argv[])
case SYS_open:
handle_open();
break;
+ case SYS_openat:
+ handle_openat();
+ break;
+ case SYS_open_by_handle_at:
+ warnx("open_by_handle_at() support not implemented!");
+ break;
case SYS_lseek:
handle_lseek();
break;
