1 /*
2 * Check decoding of inotify_add_watch and inotify_rm_watch syscalls.
3 *
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2019 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12
13 #include "scno.h"
14
15 #if defined(__NR_inotify_add_watch) && defined(__NR_inotify_rm_watch)
16
17 # include <stdio.h>
18 # include <string.h>
19 # include <unistd.h>
20
21 int
22 main(void)
23 {
24 static const struct {
25 const char *path;
26 const char *str;
27 } bogus_path_str = {
28 ARG_STR("/abc\1/def\2/ghi\3/jkl\4/mno\5/pqr\6/stu\7/vwx\10") };
29 static const kernel_ulong_t bogus_fd =
30 (kernel_ulong_t) 0xfffffeedfffffaceULL;
31 static const kernel_ulong_t bogus_mask =
32 (kernel_ulong_t) 0xffffda7affffdeadULL;
33 static const char *bogus_mask_str = "IN_ACCESS|IN_ATTRIB|"
34 "IN_CLOSE_WRITE|IN_OPEN|IN_MOVED_TO|IN_DELETE|IN_DELETE_SELF|"
35 "IN_MOVE_SELF|IN_Q_OVERFLOW|IN_IGNORED|IN_ONLYDIR|"
36 "IN_DONT_FOLLOW|IN_EXCL_UNLINK|IN_MASK_CREATE|IN_MASK_ADD|"
37 "IN_ISDIR|IN_ONESHOT|0x8ff1000";
38
39 long rc;
40 char *bogus_path = tail_memdup(bogus_path_str.path,
41 strlen(bogus_path_str.path) + 1);
42
43 rc = syscall(__NR_inotify_add_watch, 0, NULL, 0);
44 printf("inotify_add_watch(0, NULL, 0) = %s\n", sprintrc(rc));
45
46 rc = syscall(__NR_inotify_add_watch, bogus_fd, bogus_path + 4096, 0);
47 printf("inotify_add_watch(%d, %p, %u) = %s\n",
48 (int) bogus_fd, bogus_path + 4096, 0, sprintrc(rc));
49
50 rc = syscall(__NR_inotify_add_watch, bogus_fd, bogus_path, bogus_mask);
51 printf("inotify_add_watch(%d, %s, %s) = %s\n",
52 (int) bogus_fd, bogus_path_str.str, bogus_mask_str,
53 sprintrc(rc));
54
55 rc = syscall(__NR_inotify_rm_watch, 0, 0);
56 printf("inotify_rm_watch(0, 0) = %s\n", sprintrc(rc));
57
58 rc = syscall(__NR_inotify_rm_watch, bogus_fd, bogus_fd);
59 printf("inotify_rm_watch(%d, %d) = %s\n",
60 (int) bogus_fd, (int) bogus_fd, sprintrc(rc));
61
62 puts("+++ exited with 0 +++");
63
64 return 0;
65 }
66
67 #else
68
69 SKIP_MAIN_UNDEFINED("__NR_inotify_add_watch && __NR_inotify_rm_watch");
70
71 #endif