-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5abc07
commit dea5bc6
Showing
7 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ | ||
|
||
#include "util.h" | ||
|
||
#include <fcntl.h> /* Definition of O_* and S_* constants */ | ||
#include <linux/openat2.h> /* Definition of RESOLVE_* constants */ | ||
#include <sys/syscall.h> /* Definition of SYS_* constants */ | ||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
#define TEST_DIR "test_dir" | ||
#define FILENAME "foo" | ||
#define REL_FILENAME "../" TEST_DIR "/" FILENAME | ||
|
||
int main(void) { | ||
mkdir(TEST_DIR, 0700); | ||
int dirfd = open(TEST_DIR, O_DIRECTORY, 0755); | ||
test_assert(dirfd > 0); | ||
|
||
int filefd = openat(dirfd, FILENAME, O_CREAT | O_RDWR, 0600); | ||
test_assert(filefd > 0); | ||
test_assert(close(filefd) == 0); | ||
|
||
struct open_how how = {0}; | ||
how.flags = O_CREAT | O_RDONLY; | ||
how.mode = 0600; | ||
|
||
how.resolve = RESOLVE_BENEATH; | ||
filefd = syscall(SYS_openat2, dirfd, REL_FILENAME, &how, sizeof(how)); | ||
test_assert(filefd == -1); | ||
|
||
// openat2 was introduced by Linux 5.6 | ||
// if the syscall isn't supported, return immediatly | ||
if (errno == ENOSYS) { | ||
atomic_puts("EXIT-SUCCESS"); | ||
return 0; | ||
} | ||
|
||
test_assert(errno == EXDEV); | ||
|
||
how.resolve = 0; | ||
filefd = syscall(SYS_openat2, dirfd, REL_FILENAME, &how, sizeof(how)); | ||
test_assert(filefd > 0); | ||
test_assert(close(filefd) == 0); | ||
|
||
atomic_puts("EXIT-SUCCESS"); | ||
return 0; | ||
} |