-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathopenat204.c
More file actions
60 lines (52 loc) · 1.42 KB
/
openat204.c
File metadata and controls
60 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright (C) 2020 Invisible Things Lab
* Michał Kowalczyk <mkow@invisiblethingslab.com>
*/
/*
* DESCRIPTION
* Creates a file using `openat2` with bits outside of 07777 in `mode` set and
* verifies if they were ignored.
*
* WARNING
* The fact that these bits are ignored is not documented (at the time of
* writing). Failure of this test doesn't necessarily mean that a regression
* in Linux was introduced, its intention is to catch accidental interface
* changes and warn kernel developers if that happens.
*/
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include "tst_test.h"
#include "lapi/openat2.h"
#define TEST_FILE "testfile"
static struct tcase {
char *filename;
uint64_t flags;
uint64_t mode;
uint64_t resolve;
} tcases[] = {
{TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777, 0},
{TEST_FILE, 0, ~07777, 0},
};
static void verify_open(unsigned int n)
{
struct tcase *tc = &tcases[n];
struct open_how how = {
.flags = tc->flags,
.mode = tc->mode,
.resolve = tc->resolve,
};
TEST(openat2(AT_FDCWD, tc->filename, &how, sizeof(how)));
int fd = TST_RET;
if (fd == -1) {
tst_res(TFAIL | TTERRNO, "Cannot open the file");
return;
}
tst_res(TPASS, "Unknown mode bits were ignored as expected");
SAFE_CLOSE(fd);
}
static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcases),
.needs_tmpdir = 1,
.test = verify_open,
};