提交 11af135f 编写于 作者: H haotuo

1. Fix fortify interfaces name in ohos and add fortify interfaces in NDK

2. Modify macro MUSL_FORTIFY_SOURCE to _FORTIFY_SOURCE so it can work
   correctly

Issue:#I70BYR

Test: pass libc-test
Signed-off-by: Nhaotuo <haotuo@huawei.com>
Change-Id: If4d2dd64284d432dcc8dd3d8de9fd7f198a27e82
上级 82e427c0
...@@ -85,3 +85,5 @@ int t_setutf8(void); ...@@ -85,3 +85,5 @@ int t_setutf8(void);
#define __utimes_time64 utimes #define __utimes_time64 utimes
#define __wait4_time64 wait4 #define __wait4_time64 wait4
#endif #endif
#define TEST_MODE 0666
...@@ -29,7 +29,7 @@ void open_0100(void) ...@@ -29,7 +29,7 @@ void open_0100(void)
{ {
char s[] = "test"; char s[] = "test";
char buffer[80] = {0}; char buffer[80] = {0};
int fd = open(path, O_RDONLY + O_CREAT); int fd = open(path, O_RDONLY + O_CREAT, TEST_MODE);
int len = write(fd, s, sizeof(s)); int len = write(fd, s, sizeof(s));
ssize_t size = read(fd, buffer, sizeof(buffer)); ssize_t size = read(fd, buffer, sizeof(buffer));
EXPECT_EQ("open_0100", fd, 4); EXPECT_EQ("open_0100", fd, 4);
...@@ -60,7 +60,7 @@ void open_0300(void) ...@@ -60,7 +60,7 @@ void open_0300(void)
{ {
char s[] = "test"; char s[] = "test";
char buffer[80] = {0}; char buffer[80] = {0};
int fd = open(path, O_WRONLY + O_CREAT); int fd = open(path, O_WRONLY + O_CREAT, TEST_MODE);
ssize_t size = read(fd, buffer, sizeof(buffer)); ssize_t size = read(fd, buffer, sizeof(buffer));
EXPECT_EQ("open_0300", fd, 4); EXPECT_EQ("open_0300", fd, 4);
EXPECT_STREQ("open_0300", buffer, ""); EXPECT_STREQ("open_0300", buffer, "");
...@@ -90,7 +90,7 @@ void open_0500(void) ...@@ -90,7 +90,7 @@ void open_0500(void)
{ {
char s[] = "test"; char s[] = "test";
char buffer[80] = {0}; char buffer[80] = {0};
int fd = open(path, O_RDWR | O_APPEND + O_CREAT); int fd = open(path, O_RDWR | O_APPEND + O_CREAT, TEST_MODE);
ssize_t size = read(fd, buffer, sizeof(buffer)); ssize_t size = read(fd, buffer, sizeof(buffer));
EXPECT_EQ("open_0500", fd, 4); EXPECT_EQ("open_0500", fd, 4);
EXPECT_STREQ("open_0500", buffer, ""); EXPECT_STREQ("open_0500", buffer, "");
...@@ -138,7 +138,7 @@ void open_0800(void) ...@@ -138,7 +138,7 @@ void open_0800(void)
{ {
char s[] = "test"; char s[] = "test";
char buffer[80] = {0}; char buffer[80] = {0};
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
ssize_t size = read(fd, buffer, sizeof(buffer)); ssize_t size = read(fd, buffer, sizeof(buffer));
EXPECT_EQ("open_0800", fd, 4); EXPECT_EQ("open_0800", fd, 4);
EXPECT_STREQ("open_0800", buffer, ""); EXPECT_STREQ("open_0800", buffer, "");
...@@ -157,7 +157,7 @@ void open_0900(void) ...@@ -157,7 +157,7 @@ void open_0900(void)
{ {
char s[] = "test"; char s[] = "test";
char buffer[80] = {0}; char buffer[80] = {0};
int fd = open(path, O_RDWR | O_CLOEXEC + O_CREAT); int fd = open(path, O_RDWR | O_CLOEXEC + O_CREAT, TEST_MODE);
ssize_t size = read(fd, buffer, sizeof(buffer)); ssize_t size = read(fd, buffer, sizeof(buffer));
EXPECT_EQ("open_0900", fd, 4); EXPECT_EQ("open_0900", fd, 4);
EXPECT_STREQ("open_0900", buffer, ""); EXPECT_STREQ("open_0900", buffer, "");
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "functionalext.h" #include "functionalext.h"
#define TEST_MODE 0666
/** /**
* @tc.name : openat_0100 * @tc.name : openat_0100
* @tc.desc : Open /dev/null * @tc.desc : Open /dev/null
...@@ -25,13 +24,13 @@ ...@@ -25,13 +24,13 @@
*/ */
void openat_0100(void) void openat_0100(void)
{ {
int ret = openat(0, "/dev/null", O_CREAT); int ret = openat(0, "/dev/null", O_CREAT, TEST_MODE);
EXPECT_NE("openat_0100", ret, ERREXPECT); EXPECT_NE("openat_0100", ret, ERREXPECT);
ret = openat(0, "/dev/null", O_TMPFILE); ret = openat(0, "/dev/null", O_TMPFILE, TEST_MODE);
EXPECT_EQ("openat_0100", ret, ERREXPECT); EXPECT_EQ("openat_0100", ret, ERREXPECT);
ret = openat(0, "/dev/null", O_RDONLY, TEST_MODE); ret = openat(0, "/dev/null", O_RDONLY);
EXPECT_NE("openat_0100", ret, ERREXPECT); EXPECT_NE("openat_0100", ret, ERREXPECT);
} }
...@@ -42,13 +41,13 @@ void openat_0100(void) ...@@ -42,13 +41,13 @@ void openat_0100(void)
*/ */
void openat_0200(void) void openat_0200(void)
{ {
int ret = openat(0, "openat_test", O_CREAT); int ret = openat(0, "openat_test", O_CREAT, TEST_MODE);
EXPECT_EQ("openat_0200", ret, ERREXPECT); EXPECT_EQ("openat_0200", ret, ERREXPECT);
ret = openat(0, "openat_test", O_TMPFILE); ret = openat(0, "openat_test", O_TMPFILE, TEST_MODE);
EXPECT_EQ("openat_0200", ret, ERREXPECT); EXPECT_EQ("openat_0200", ret, ERREXPECT);
ret = openat(0, "openat_test", O_RDONLY, TEST_MODE); ret = openat(0, "openat_test", O_RDONLY);
EXPECT_EQ("openat_0200", ret, ERREXPECT); EXPECT_EQ("openat_0200", ret, ERREXPECT);
} }
......
...@@ -31,7 +31,7 @@ void semtimedop_0100(void) ...@@ -31,7 +31,7 @@ void semtimedop_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
......
...@@ -29,7 +29,7 @@ void getpagesize_0100() ...@@ -29,7 +29,7 @@ void getpagesize_0100()
system("getconf PAGE_SIZE > /data/1.txt"); system("getconf PAGE_SIZE > /data/1.txt");
FILE *fd; FILE *fd;
fd = fopen("/data/1.txt", "r"); fd = fopen("/data/1.txt", "r");
fread(list, sizeof(list), 10, fd); fread(list, sizeof(list) / sizeof(list[0]), sizeof(*list), fd);
EXPECT_EQ("getpagesize_0100", page, atoi(list)); EXPECT_EQ("getpagesize_0100", page, atoi(list));
remove("/data/1.txt"); remove("/data/1.txt");
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "filepath_util.h" #include "filepath_util.h"
const char *str = "Hello"; const char *str = "Hello";
/** /**
* @tc.name : copy_file_range_0100 * @tc.name : copy_file_range_0100
* @tc.desc : Copy a range of data from one file to another * @tc.desc : Copy a range of data from one file to another
...@@ -36,7 +35,7 @@ void copy_file_range_0100(void) ...@@ -36,7 +35,7 @@ void copy_file_range_0100(void)
FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in);
FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out);
fd_in = open(path_in, O_RDWR | O_CREAT); fd_in = open(path_in, O_RDWR | O_CREAT, TEST_MODE);
if (fd_in == -1) { if (fd_in == -1) {
t_error("%s open path_in failed\n", __func__); t_error("%s open path_in failed\n", __func__);
return; return;
...@@ -51,7 +50,7 @@ void copy_file_range_0100(void) ...@@ -51,7 +50,7 @@ void copy_file_range_0100(void)
close(fd_in); close(fd_in);
fd_in = open(path_in, O_RDONLY); fd_in = open(path_in, O_RDONLY);
fd_out = open(path_out, O_RDWR | O_CREAT); fd_out = open(path_out, O_RDWR | O_CREAT, TEST_MODE);
if (fd_out == -1) { if (fd_out == -1) {
t_error("%s open path_out failed\n", __func__); t_error("%s open path_out failed\n", __func__);
return; return;
...@@ -115,7 +114,7 @@ void copy_file_range_0300(void) ...@@ -115,7 +114,7 @@ void copy_file_range_0300(void)
FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in);
FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out);
fd_in = open(path_in, O_WRONLY | O_CREAT); fd_in = open(path_in, O_WRONLY | O_CREAT, TEST_MODE);
if (fd_in == -1) { if (fd_in == -1) {
t_error("%s open path_in failed\n", __func__); t_error("%s open path_in failed\n", __func__);
return; return;
...@@ -130,7 +129,7 @@ void copy_file_range_0300(void) ...@@ -130,7 +129,7 @@ void copy_file_range_0300(void)
close(fd_in); close(fd_in);
fd_in = open(path_in, O_WRONLY); fd_in = open(path_in, O_WRONLY);
fd_out = open(path_out, O_RDONLY | O_CREAT); fd_out = open(path_out, O_RDONLY | O_CREAT, TEST_MODE);
if (fd_out == -1) { if (fd_out == -1) {
t_error("%s open path_out failed\n", __func__); t_error("%s open path_out failed\n", __func__);
return; return;
......
...@@ -29,7 +29,7 @@ void fallocate_0100() ...@@ -29,7 +29,7 @@ void fallocate_0100()
{ {
char str[] = "this is a fatest\n"; char str[] = "this is a fatest\n";
char buffer[1024] = {0}; char buffer[1024] = {0};
int fd = open("fatest.txt", O_RDWR | O_CREAT); int fd = open("fatest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fallocate_0100", fd >= 0); EXPECT_TRUE("fallocate_0100", fd >= 0);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
EXPECT_EQ("fallocate_0100", retwrite, SIZE); EXPECT_EQ("fallocate_0100", retwrite, SIZE);
...@@ -48,7 +48,7 @@ void fallocate_0200(void) ...@@ -48,7 +48,7 @@ void fallocate_0200(void)
{ {
char str[] = "this is a fatest\n"; char str[] = "this is a fatest\n";
char buffer[1024] = {0}; char buffer[1024] = {0};
int fd = open("fatest.txt", O_RDWR | O_CREAT); int fd = open("fatest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fallocate_0200", fd >= 0); EXPECT_TRUE("fallocate_0200", fd >= 0);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
EXPECT_EQ("fallocate_0200", retwrite, SIZE); EXPECT_EQ("fallocate_0200", retwrite, SIZE);
...@@ -67,7 +67,7 @@ void fallocate_0300(void) ...@@ -67,7 +67,7 @@ void fallocate_0300(void)
{ {
char str[] = "this is a fatest\n"; char str[] = "this is a fatest\n";
char buffer[1024] = {0}; char buffer[1024] = {0};
int fd = open("fatest.txt", O_RDWR | O_CREAT); int fd = open("fatest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fallocate_0300", fd >= 0); EXPECT_TRUE("fallocate_0300", fd >= 0);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
EXPECT_EQ("fallocate_0300", retwrite, SIZE); EXPECT_EQ("fallocate_0300", retwrite, SIZE);
......
...@@ -30,7 +30,7 @@ void fgetxattr_0100(void) ...@@ -30,7 +30,7 @@ void fgetxattr_0100(void)
char name[] = "user.x"; char name[] = "user.x";
char value[] = "the past is not dead."; char value[] = "the past is not dead.";
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
void flock_0100(void) void flock_0100(void)
{ {
int result = -1; int result = -1;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0100", fd, -1); EXPECT_NE("flock_0100", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
...@@ -43,7 +43,7 @@ void flock_0100(void) ...@@ -43,7 +43,7 @@ void flock_0100(void)
void flock_0200(void) void flock_0200(void)
{ {
int result = -1; int result = -1;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0200", fd, -1); EXPECT_NE("flock_0200", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
...@@ -61,7 +61,7 @@ void flock_0200(void) ...@@ -61,7 +61,7 @@ void flock_0200(void)
void flock_0300(void) void flock_0300(void)
{ {
int result = -1; int result = -1;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0300", fd, -1); EXPECT_NE("flock_0300", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
...@@ -79,7 +79,7 @@ void flock_0300(void) ...@@ -79,7 +79,7 @@ void flock_0300(void)
void flock_0400(void) void flock_0400(void)
{ {
int result = -1; int result = -1;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0400", fd, -1); EXPECT_NE("flock_0400", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
...@@ -97,7 +97,7 @@ void flock_0400(void) ...@@ -97,7 +97,7 @@ void flock_0400(void)
void flock_0500(void) void flock_0500(void)
{ {
int result = -1; int result = -1;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0500", fd, -1); EXPECT_NE("flock_0500", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
...@@ -126,7 +126,7 @@ void flock_0600(void) ...@@ -126,7 +126,7 @@ void flock_0600(void)
void flock_0700() void flock_0700()
{ {
int result = 0; int result = 0;
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666); int fd = open("/data/test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("flock_0700", fd, -1); EXPECT_NE("flock_0700", fd, -1);
lseek(fd, 2, SEEK_SET); lseek(fd, 2, SEEK_SET);
......
...@@ -29,7 +29,7 @@ const int size = 3; ...@@ -29,7 +29,7 @@ const int size = 3;
*/ */
void getxattr_0100(void) void getxattr_0100(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
return; return;
......
...@@ -29,7 +29,7 @@ const int size = 3; ...@@ -29,7 +29,7 @@ const int size = 3;
*/ */
void lremovexattr_0100(void) void lremovexattr_0100(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
return; return;
......
...@@ -29,7 +29,7 @@ const int size = 3; ...@@ -29,7 +29,7 @@ const int size = 3;
*/ */
void lsetxattr_0100(void) void lsetxattr_0100(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
return; return;
......
...@@ -104,7 +104,7 @@ void remap_file_pages_0100(void) ...@@ -104,7 +104,7 @@ void remap_file_pages_0100(void)
{ {
char str[LEN] = {0}; char str[LEN] = {0};
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
} }
......
...@@ -33,7 +33,7 @@ void removexattr_0100(void) ...@@ -33,7 +33,7 @@ void removexattr_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
......
...@@ -46,7 +46,7 @@ void sendfile_0100(void) ...@@ -46,7 +46,7 @@ void sendfile_0100(void)
t_error("%s failed: open. fromfd = %d\n", __func__, fromfd); t_error("%s failed: open. fromfd = %d\n", __func__, fromfd);
} }
int tofd = open(tofile, O_WRONLY | O_CREAT); int tofd = open(tofile, O_WRONLY | O_CREAT, TEST_MODE);
if (tofd < 0) { if (tofd < 0) {
t_error("%s failed: open. tofd = %d\n", __func__, tofd); t_error("%s failed: open. tofd = %d\n", __func__, tofd);
} }
......
...@@ -33,7 +33,7 @@ void setxattr_0100(void) ...@@ -33,7 +33,7 @@ void setxattr_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
......
...@@ -35,12 +35,12 @@ void splice_0100(void) ...@@ -35,12 +35,12 @@ void splice_0100(void)
FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile);
FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile); FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile);
int fromfd = open(fromfile, O_RDWR | O_CREAT); int fromfd = open(fromfile, O_RDWR | O_CREAT, TEST_MODE);
if (fromfd < 0) { if (fromfd < 0) {
t_error("%s failed: fromfd = %d\n", __func__, fromfd); t_error("%s failed: fromfd = %d\n", __func__, fromfd);
} }
int tofd = open(tofile, O_RDWR | O_CREAT); int tofd = open(tofile, O_RDWR | O_CREAT, TEST_MODE);
if (tofd < 0) { if (tofd < 0) {
t_error("%s failed: tofd = %d\n", __func__, tofd); t_error("%s failed: tofd = %d\n", __func__, tofd);
} }
......
...@@ -32,7 +32,7 @@ void sync_file_range_0100(void) ...@@ -32,7 +32,7 @@ void sync_file_range_0100(void)
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
return; return;
...@@ -77,7 +77,7 @@ void sync_file_range_0300(void) ...@@ -77,7 +77,7 @@ void sync_file_range_0300(void)
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
return; return;
...@@ -106,7 +106,7 @@ void sync_file_range_0400(void) ...@@ -106,7 +106,7 @@ void sync_file_range_0400(void)
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
return; return;
......
...@@ -30,7 +30,7 @@ void syncfs_0100(void) ...@@ -30,7 +30,7 @@ void syncfs_0100(void)
errno = 0; errno = 0;
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH("syncfs.txt", path); FILE_ABSOLUTE_PATH("syncfs.txt", path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
return; return;
......
...@@ -37,7 +37,7 @@ void isatty_0100() ...@@ -37,7 +37,7 @@ void isatty_0100()
*/ */
void isatty_0200() void isatty_0200()
{ {
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
int result = isatty(fd); int result = isatty(fd);
EXPECT_EQ("isatty_0200", result, 0); EXPECT_EQ("isatty_0200", result, 0);
close(fd); close(fd);
......
...@@ -27,7 +27,7 @@ const int SIZE = 3; ...@@ -27,7 +27,7 @@ const int SIZE = 3;
*/ */
void lockf_0100(void) void lockf_0100(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
return; return;
...@@ -50,7 +50,7 @@ void lockf_0100(void) ...@@ -50,7 +50,7 @@ void lockf_0100(void)
*/ */
void lockf_0200(void) void lockf_0200(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
return; return;
...@@ -73,7 +73,7 @@ void lockf_0200(void) ...@@ -73,7 +73,7 @@ void lockf_0200(void)
*/ */
void lockf_0300(void) void lockf_0300(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
...@@ -98,7 +98,7 @@ void lockf_0300(void) ...@@ -98,7 +98,7 @@ void lockf_0300(void)
*/ */
void lockf_0400(void) void lockf_0400(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
......
...@@ -102,27 +102,28 @@ void ptsname_r_0400(void) ...@@ -102,27 +102,28 @@ void ptsname_r_0400(void)
/** /**
* @tc.name : posix_openpt_0100 * @tc.name : posix_openpt_0100
* @tc.desc : Open the ptmx file in the dev directory (success) * @tc.desc : Open the ptmx file using flag O_RDWR (success)
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
void posix_openpt_0100(void) void posix_openpt_0100(void)
{ {
int amaster, aslave; int amaster, aslave;
int ret = posix_openpt(O_RDWR | O_CREAT); int ret = posix_openpt(O_RDWR);
EXPECT_NE("posix_openpt_0100", ret, ERREXPECT); EXPECT_NE("posix_openpt_0100", ret, ERREXPECT);
ret = close(ret); close(ret);
} }
/** /**
* @tc.name : posix_openpt_0200 * @tc.name : posix_openpt_0200
* @tc.desc : Open the ptmx file in the dev directory (failed) * @tc.desc : Open the ptmx file using flag O_RDWR | O_NOCTTY (success)
* @tc.level : Level 2 * @tc.level : Level 2
*/ */
void posix_openpt_0200(void) void posix_openpt_0200(void)
{ {
errno = ENOSPC; errno = ENOSPC;
int ret = posix_openpt(O_EXCL | O_CREAT); int ret = posix_openpt(O_RDWR | O_NOCTTY);
EXPECT_EQ("posix_openpt_0200", ret, ERREXPECT); EXPECT_NE("posix_openpt_0200", ret, ERREXPECT);
close(ret);
} }
int main(void) int main(void)
......
...@@ -37,9 +37,7 @@ void realpath_0100(void) ...@@ -37,9 +37,7 @@ void realpath_0100(void)
void realpath_0200(void) void realpath_0200(void)
{ {
char actualPath[4096] = {0}; char actualPath[4096] = {0};
char *ret = realpath(NULL, actualPath); char *ret = realpath("/system/bin/../mypth", actualPath);
EXPECT_PTREQ("realpath_0200", ret, NULL);
ret = realpath("/system/bin/../mypth", actualPath);
EXPECT_PTREQ("realpath_0200", ret, NULL); EXPECT_PTREQ("realpath_0200", ret, NULL);
ret = realpath("/system/bin/../etc", NULL); ret = realpath("/system/bin/../etc", NULL);
EXPECT_STREQ("realpath_0200", ret, "/system/etc"); EXPECT_STREQ("realpath_0200", ret, "/system/etc");
......
...@@ -23,7 +23,7 @@ const char *path = "madvise_function_test.c"; ...@@ -23,7 +23,7 @@ const char *path = "madvise_function_test.c";
static int openfile(void) static int openfile(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("open file failed\n"); t_error("open file failed\n");
return -1; return -1;
......
...@@ -23,7 +23,7 @@ const char *path = "posix_madvise_function_test.c"; ...@@ -23,7 +23,7 @@ const char *path = "posix_madvise_function_test.c";
static int openfile(void) static int openfile(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("open file failed\n"); t_error("open file failed\n");
return -1; return -1;
......
...@@ -29,7 +29,7 @@ void fexecve_0100(void) ...@@ -29,7 +29,7 @@ void fexecve_0100(void)
if (fpid == 0) { if (fpid == 0) {
char *argv[] = {"./fexecverely", NULL}; char *argv[] = {"./fexecverely", NULL};
char *environ[] = {0, NULL}; char *environ[] = {0, NULL};
int fd = open("fexecverely", O_RDONLY, 0777); int fd = open("fexecverely", O_RDONLY);
int ret = fexecve(fd, argv, environ); int ret = fexecve(fd, argv, environ);
EXPECT_NE("fexecve_0100", ret, -1); EXPECT_NE("fexecve_0100", ret, -1);
} }
......
...@@ -35,14 +35,14 @@ void poll_0100(void) ...@@ -35,14 +35,14 @@ void poll_0100(void)
struct pollfd fds[2]; struct pollfd fds[2];
int time_delay = 2000; int time_delay = 2000;
int fd1 = open(path1, O_WRONLY | O_CREAT); int fd1 = open(path1, O_WRONLY | O_CREAT, TEST_MODE);
if (fd1 < 0) { if (fd1 < 0) {
t_error("%s open path1 failed\n", __func__); t_error("%s open path1 failed\n", __func__);
} }
write(fd1, str1, strlen(str1) + 1); write(fd1, str1, strlen(str1) + 1);
close(fd1); close(fd1);
int fd2 = open(path2, O_WRONLY | O_CREAT); int fd2 = open(path2, O_WRONLY | O_CREAT, TEST_MODE);
if (fd2 < 0) { if (fd2 < 0) {
t_error("%s open path2 failed\n", __func__); t_error("%s open path2 failed\n", __func__);
} }
...@@ -108,29 +108,9 @@ void poll_0200(void) ...@@ -108,29 +108,9 @@ void poll_0200(void)
} }
} }
/*
* @tc.name : poll_0300
* @tc.desc : When the parameter nfds is invalid, test the return value of the function
* @tc.level : Level 2
*/
void poll_0300(void)
{
struct pollfd fds[2];
fds[0].fd = 1;
fds[0].events = POLLIN;
fds[1].fd = 1;
fds[1].events = POLLIN;
int result = poll(fds, -1, 1);
if (result != -1) {
t_error("%s poll should be failed\n", __func__);
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
poll_0100(); poll_0100();
poll_0200(); poll_0200();
poll_0300();
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
void chmod_0100(void) void chmod_0100(void)
{ {
struct stat buf; struct stat buf;
open("test.txt", O_RDWR | O_CREAT); open("test.txt", O_RDWR | O_CREAT, TEST_MODE);
int result = chmod("test.txt", int result = chmod("test.txt",
S_IRUSR | S_ISGID | S_ISVTX | S_IWUSR | S_IROTH | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IRUSR | S_ISGID | S_ISVTX | S_IWUSR | S_IROTH | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH |
S_IWOTH | S_IXOTH); S_IWOTH | S_IXOTH);
...@@ -44,7 +44,7 @@ void chmod_0200(void) ...@@ -44,7 +44,7 @@ void chmod_0200(void)
{ {
struct stat buf; struct stat buf;
open("test.txt", O_RDWR | O_CREAT); open("test.txt", O_RDWR | O_CREAT, TEST_MODE);
int result = chmod("test.txt", S_IRWXU | S_IRWXG | S_IRWXO); int result = chmod("test.txt", S_IRWXU | S_IRWXG | S_IRWXO);
stat("test.txt", &buf); stat("test.txt", &buf);
EXPECT_EQ("chmod_0200", result, 0); EXPECT_EQ("chmod_0200", result, 0);
......
...@@ -28,7 +28,7 @@ void fchmod_0100() ...@@ -28,7 +28,7 @@ void fchmod_0100()
{ {
struct stat buf; struct stat buf;
const char *path = "/data/test.txt"; const char *path = "/data/test.txt";
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("fchmod_0100", fd, -1); EXPECT_NE("fchmod_0100", fd, -1);
int result = fchmod(fd, int result = fchmod(fd,
...@@ -50,7 +50,7 @@ void fchmod_0200() ...@@ -50,7 +50,7 @@ void fchmod_0200()
{ {
struct stat buf; struct stat buf;
const char *path = "/data/test.txt"; const char *path = "/data/test.txt";
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
int result = fchmod(fd, S_IRWXU | S_IRWXG | S_IRWXO); int result = fchmod(fd, S_IRWXU | S_IRWXG | S_IRWXO);
stat(path, &buf); stat(path, &buf);
EXPECT_EQ("fchmod_0200", result, 0); EXPECT_EQ("fchmod_0200", result, 0);
......
...@@ -33,7 +33,7 @@ void fchmodat_0100(void) ...@@ -33,7 +33,7 @@ void fchmodat_0100(void)
struct stat buf; struct stat buf;
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); FILE_ABSOLUTE_PATH(STR_TEST_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
int result = fchmodat(fd, int result = fchmodat(fd,
path, path,
S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH |
...@@ -57,7 +57,7 @@ void fchmodat_0200(void) ...@@ -57,7 +57,7 @@ void fchmodat_0200(void)
struct stat buf; struct stat buf;
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); FILE_ABSOLUTE_PATH(STR_TEST_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
int result = fchmodat(fd, int result = fchmodat(fd,
path, path,
S_IRWXU | S_IRWXG | S_IRWXO, S_IRWXU | S_IRWXG | S_IRWXO,
......
...@@ -33,7 +33,7 @@ void fstatat_0100(void) ...@@ -33,7 +33,7 @@ void fstatat_0100(void)
{ {
const char *ptr = "fstatattest.txt"; const char *ptr = "fstatattest.txt";
struct stat st; struct stat st;
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fstatat_0100", fd >= 0); EXPECT_TRUE("fstatat_0100", fd >= 0);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
int ret = fstatat(AT_FDCWD, ptr, &st, 0); int ret = fstatat(AT_FDCWD, ptr, &st, 0);
...@@ -57,7 +57,7 @@ void fstatat_0200(void) ...@@ -57,7 +57,7 @@ void fstatat_0200(void)
{ {
const char *ptr = "fstatattest.txt"; const char *ptr = "fstatattest.txt";
struct stat st; struct stat st;
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fstatat_0200", fd >= 0); EXPECT_TRUE("fstatat_0200", fd >= 0);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
const char *softptr = "./fstatattest.txt.soft"; const char *softptr = "./fstatattest.txt.soft";
...@@ -89,7 +89,7 @@ void fstatat_0300(void) ...@@ -89,7 +89,7 @@ void fstatat_0300(void)
FILE_ABSOLUTE_PATH("fstatattest.txt", ptr); FILE_ABSOLUTE_PATH("fstatattest.txt", ptr);
struct stat st; struct stat st;
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fstatat_0300", fd >= 0); EXPECT_TRUE("fstatat_0300", fd >= 0);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
int ret = fstatat(0, ptr, &st, 0); int ret = fstatat(0, ptr, &st, 0);
...@@ -112,7 +112,7 @@ void fstatat_time64_0100(void) ...@@ -112,7 +112,7 @@ void fstatat_time64_0100(void)
{ {
const char *ptr = "fstatat_time64_test.txt"; const char *ptr = "fstatat_time64_test.txt";
struct stat st; struct stat st;
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fstatat_0100", fd >= 0); EXPECT_TRUE("fstatat_0100", fd >= 0);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
int ret = __fstatat_time64(AT_FDCWD, ptr, &st, 0); int ret = __fstatat_time64(AT_FDCWD, ptr, &st, 0);
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h" #include "filepath_util.h"
#define TEST_MODE 0666
/** /**
* @tc.name : mknod_0100 * @tc.name : mknod_0100
* @tc.desc : Create file node * @tc.desc : Create file node
......
...@@ -32,7 +32,7 @@ void utimensat_0100(void) ...@@ -32,7 +32,7 @@ void utimensat_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}};
int result = utimensat(fd, path, times, 0); int result = utimensat(fd, path, times, 0);
...@@ -82,7 +82,7 @@ void utimensat_time64_0100(void) ...@@ -82,7 +82,7 @@ void utimensat_time64_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}};
int result = __utimensat_time64(fd, path, times, 0); int result = __utimensat_time64(fd, path, times, 0);
......
...@@ -51,7 +51,7 @@ void dprintf_0200(void) ...@@ -51,7 +51,7 @@ void dprintf_0200(void)
void dprintf_0300(void) void dprintf_0300(void)
{ {
const char *path = "/data/test.txt"; const char *path = "/data/test.txt";
int fd = open(path, O_CREAT | O_WRONLY); int fd = open(path, O_CREAT | O_WRONLY, TEST_MODE);
EXPECT_NE("dprintf_0300", fd, -1); EXPECT_NE("dprintf_0300", fd, -1);
int result = dprintf(fd, "This is a test!"); int result = dprintf(fd, "This is a test!");
...@@ -72,7 +72,7 @@ void dprintf_0300(void) ...@@ -72,7 +72,7 @@ void dprintf_0300(void)
void dprintf_0400(void) void dprintf_0400(void)
{ {
const char *path = "/data/test.txt"; const char *path = "/data/test.txt";
int fd = open(path, O_CREAT | O_RDONLY); int fd = open(path, O_CREAT | O_RDONLY, TEST_MODE);
EXPECT_NE("dprintf_0400", fd, -1); EXPECT_NE("dprintf_0400", fd, -1);
int result = dprintf(fd, "This is a test!"); int result = dprintf(fd, "This is a test!");
......
...@@ -57,7 +57,7 @@ void fgetws_0200() ...@@ -57,7 +57,7 @@ void fgetws_0200()
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("fgetws_0100", fptr, NULL); EXPECT_PTRNE("fgetws_0100", fptr, NULL);
fwrite(line, sizeof(char), 100, fptr); fwrite(line, sizeof(line) / sizeof(wchar_t), sizeof(*line), fptr);
fflush(fptr); fflush(fptr);
wchar_t *ch = fgetws(wrstring, EINVAL, fptr); wchar_t *ch = fgetws(wrstring, EINVAL, fptr);
......
...@@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt"; ...@@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt";
void getchar_0100(void) void getchar_0100(void)
{ {
char str[] = "t"; char str[] = "t";
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
} }
......
...@@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt"; ...@@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt";
void getchar_unlocked_0100(void) void getchar_unlocked_0100(void)
{ {
char str[] = "r"; char str[] = "r";
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
} }
......
...@@ -25,7 +25,7 @@ void rename_0100(void) ...@@ -25,7 +25,7 @@ void rename_0100(void)
{ {
const char *oldname = "oldfile.txt"; const char *oldname = "oldfile.txt";
const char *newname = "newfile.txt"; const char *newname = "newfile.txt";
int fd = open(oldname, O_RDONLY | O_CREAT); int fd = open(oldname, O_RDONLY | O_CREAT, TEST_MODE);
EXPECT_TRUE("rename_0100", fd != -1); EXPECT_TRUE("rename_0100", fd != -1);
close(fd); close(fd);
...@@ -61,7 +61,7 @@ void rename_0300(void) ...@@ -61,7 +61,7 @@ void rename_0300(void)
{ {
const char *oldname = "oldfile.txt"; const char *oldname = "oldfile.txt";
const char *newname = "newfile.txt"; const char *newname = "newfile.txt";
int fd_old = open(oldname, O_RDWR | O_CREAT); int fd_old = open(oldname, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("rename_0300", fd_old != -1); EXPECT_TRUE("rename_0300", fd_old != -1);
char str_old[] = "old"; char str_old[] = "old";
...@@ -69,7 +69,7 @@ void rename_0300(void) ...@@ -69,7 +69,7 @@ void rename_0300(void)
EXPECT_TRUE("rename_0300", ret_old > 0); EXPECT_TRUE("rename_0300", ret_old > 0);
close(fd_old); close(fd_old);
int fd_new = open(newname, O_RDWR | O_CREAT); int fd_new = open(newname, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("rename_0100", fd_new != -1); EXPECT_TRUE("rename_0100", fd_new != -1);
char str_new[] = "new"; char str_new[] = "new";
......
...@@ -37,7 +37,7 @@ void vdprintf_0100(void) ...@@ -37,7 +37,7 @@ void vdprintf_0100(void)
{ {
char *value = "asdf"; char *value = "asdf";
char buffer[100] = {0}; char buffer[100] = {0};
int fp = open("/data/temp_vdprintf.txt", O_RDWR | O_CREAT); int fp = open("/data/temp_vdprintf.txt", O_RDWR | O_CREAT, TEST_MODE);
if (fp < 0) { if (fp < 0) {
t_error("%s open failed", __func__); t_error("%s open failed", __func__);
return; return;
......
...@@ -25,7 +25,7 @@ const int FAILED = -1; ...@@ -25,7 +25,7 @@ const int FAILED = -1;
*/ */
void dup3_0100(void) void dup3_0100(void)
{ {
int fd = open("/data/dup3test.txt", O_RDWR | O_CREAT); int fd = open("/data/dup3test.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("dup3_0100", fd >= 0); EXPECT_TRUE("dup3_0100", fd >= 0);
int ret = dup3(fd, fileno(stderr), O_CLOEXEC); int ret = dup3(fd, fileno(stderr), O_CLOEXEC);
EXPECT_EQ("dup3_0100", ret, fileno(stderr)); EXPECT_EQ("dup3_0100", ret, fileno(stderr));
...@@ -53,7 +53,7 @@ void dup3_0200(void) ...@@ -53,7 +53,7 @@ void dup3_0200(void)
void dup3_0300(void) void dup3_0300(void)
{ {
int newfd = -1; int newfd = -1;
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("dup3_0300", fd >= 0); EXPECT_TRUE("dup3_0300", fd >= 0);
int ret = dup3(fd, newfd, O_CLOEXEC); int ret = dup3(fd, newfd, O_CLOEXEC);
EXPECT_EQ("dup3_0300", ret, FAILED); EXPECT_EQ("dup3_0300", ret, FAILED);
......
...@@ -32,7 +32,7 @@ void faccessat_0100(void) ...@@ -32,7 +32,7 @@ void faccessat_0100(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("faccessat_0100", fd >= 0); EXPECT_TRUE("faccessat_0100", fd >= 0);
int isExist = faccessat(fd, ptr, F_OK, 0); int isExist = faccessat(fd, ptr, F_OK, 0);
EXPECT_EQ("faccessat_0100", isExist, SUCCESS); EXPECT_EQ("faccessat_0100", isExist, SUCCESS);
...@@ -119,7 +119,7 @@ void faccessat_0600(void) ...@@ -119,7 +119,7 @@ void faccessat_0600(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("faccessat_0600", fd >= 0); EXPECT_TRUE("faccessat_0600", fd >= 0);
int isExecute = faccessat(fd, ptr, X_OK, 0); int isExecute = faccessat(fd, ptr, X_OK, 0);
EXPECT_EQ("faccessat_0600", isExecute, FAILED); EXPECT_EQ("faccessat_0600", isExecute, FAILED);
...@@ -153,7 +153,7 @@ void faccessat_0800(void) ...@@ -153,7 +153,7 @@ void faccessat_0800(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("faccessat_0800", fd >= 0); EXPECT_TRUE("faccessat_0800", fd >= 0);
int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0);
EXPECT_EQ("faccessat_0800", isExecute, FAILED); EXPECT_EQ("faccessat_0800", isExecute, FAILED);
...@@ -207,7 +207,7 @@ void faccessat_1100(void) ...@@ -207,7 +207,7 @@ void faccessat_1100(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("faccessat_1100", fd >= 0); EXPECT_TRUE("faccessat_1100", fd >= 0);
int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS);
EXPECT_EQ("faccessat_1100", isExecute, FAILED); EXPECT_EQ("faccessat_1100", isExecute, FAILED);
......
...@@ -33,7 +33,7 @@ const int COUNT_NEFATIVE = -1; ...@@ -33,7 +33,7 @@ const int COUNT_NEFATIVE = -1;
*/ */
void fchown_0100() void fchown_0100()
{ {
int fd = open("test.txt", O_RDONLY | O_CREAT); int fd = open("test.txt", O_RDONLY | O_CREAT, TEST_MODE);
int result = fchown(fd, 0, 0); int result = fchown(fd, 0, 0);
struct stat buff; struct stat buff;
EXPECT_EQ("fchown_0100", result, COUNT_ZERO); EXPECT_EQ("fchown_0100", result, COUNT_ZERO);
...@@ -50,7 +50,7 @@ void fchown_0100() ...@@ -50,7 +50,7 @@ void fchown_0100()
*/ */
void fchown_0200() void fchown_0200()
{ {
int fd = open("test.txt", O_RDONLY | O_CREAT); int fd = open("test.txt", O_RDONLY | O_CREAT, TEST_MODE);
int result = fchown(fd, 0, -1); int result = fchown(fd, 0, -1);
struct stat buff; struct stat buff;
EXPECT_EQ("fchown_0200", result, COUNT_ZERO); EXPECT_EQ("fchown_0200", result, COUNT_ZERO);
...@@ -67,7 +67,7 @@ void fchown_0200() ...@@ -67,7 +67,7 @@ void fchown_0200()
*/ */
void fchown_0300() void fchown_0300()
{ {
int fd = open("test.txt", O_RDONLY | O_CREAT); int fd = open("test.txt", O_RDONLY | O_CREAT, TEST_MODE);
int result = fchown(fd, -1, 0); int result = fchown(fd, -1, 0);
struct stat buff; struct stat buff;
EXPECT_EQ("fchown_0300", result, COUNT_ZERO); EXPECT_EQ("fchown_0300", result, COUNT_ZERO);
...@@ -84,7 +84,7 @@ void fchown_0300() ...@@ -84,7 +84,7 @@ void fchown_0300()
*/ */
void fchown_0400() void fchown_0400()
{ {
int fd = open("test.txt", O_RDONLY | O_CREAT); int fd = open("test.txt", O_RDONLY | O_CREAT, TEST_MODE);
close(fd); close(fd);
int result = fchown(fd, 0, 0); int result = fchown(fd, 0, 0);
EXPECT_EQ("fchown_0400", result, COUNT_NEFATIVE); EXPECT_EQ("fchown_0400", result, COUNT_NEFATIVE);
...@@ -98,7 +98,7 @@ void fchown_0400() ...@@ -98,7 +98,7 @@ void fchown_0400()
*/ */
void fchown_0500() void fchown_0500()
{ {
int fd = open("test.txt", O_RDONLY | O_CREAT); int fd = open("test.txt", O_RDONLY | O_CREAT, TEST_MODE);
int result = fchown(-1, 0, 0); int result = fchown(-1, 0, 0);
EXPECT_EQ("fchown_0500", result, COUNT_NEFATIVE); EXPECT_EQ("fchown_0500", result, COUNT_NEFATIVE);
close(fd); close(fd);
......
...@@ -28,7 +28,7 @@ void fchownat_0100(void) ...@@ -28,7 +28,7 @@ void fchownat_0100(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fchownat_0100", fd >= 0); EXPECT_TRUE("fchownat_0100", fd >= 0);
int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW);
EXPECT_EQ("fchownat_0100", ret, 0); EXPECT_EQ("fchownat_0100", ret, 0);
...@@ -50,7 +50,7 @@ void fchownat_0200(void) ...@@ -50,7 +50,7 @@ void fchownat_0200(void)
{ {
char ptr[PATH_MAX] = {0}; char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr);
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fchownat_0200", fd >= 0); EXPECT_TRUE("fchownat_0200", fd >= 0);
int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW);
EXPECT_EQ("fchownat_0200", ret, 0); EXPECT_EQ("fchownat_0200", ret, 0);
......
...@@ -30,7 +30,7 @@ void fdatasync_0100() ...@@ -30,7 +30,7 @@ void fdatasync_0100()
{ {
char str[] = "hello"; char str[] = "hello";
char buffer[1024] = {"\0"}; char buffer[1024] = {"\0"};
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("fdatasync_0100", fd, -1); EXPECT_NE("fdatasync_0100", fd, -1);
write(fd, str, sizeof(str)); write(fd, str, sizeof(str));
...@@ -54,7 +54,7 @@ void fdatasync_0200() ...@@ -54,7 +54,7 @@ void fdatasync_0200()
{ {
char str[] = "hello\n"; char str[] = "hello\n";
char buffer[1024] = {"\0"}; char buffer[1024] = {"\0"};
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_NE("fdatasync_0100", fd, -1); EXPECT_NE("fdatasync_0100", fd, -1);
close(fd); close(fd);
......
...@@ -26,7 +26,7 @@ const char *path = "/data/test.txt"; ...@@ -26,7 +26,7 @@ const char *path = "/data/test.txt";
*/ */
void fsync_0100(void) void fsync_0100(void)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("fsync_0100", fd >= 0); EXPECT_TRUE("fsync_0100", fd >= 0);
int result = fsync(fd); int result = fsync(fd);
......
...@@ -36,7 +36,7 @@ void lseek64_0100(void) ...@@ -36,7 +36,7 @@ void lseek64_0100(void)
{ {
off64_t DataArry[TEST_BUFFER_SIZE] = {1, 2, 4, 8}; off64_t DataArry[TEST_BUFFER_SIZE] = {1, 2, 4, 8};
off64_t offset = 0; off64_t offset = 0;
int fd = open("lseek64_function_test.c", O_RDWR | O_CREAT); int fd = open("lseek64_function_test.c", O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
t_error("open file failed\n"); t_error("open file failed\n");
return; return;
...@@ -63,7 +63,7 @@ void lseek64_0100(void) ...@@ -63,7 +63,7 @@ void lseek64_0100(void)
void lseek_0100(void) void lseek_0100(void)
{ {
char *wrstring = "This is a test sample!"; char *wrstring = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0100", 0, fd); EXPECT_STRLT("lseek_0100", 0, fd);
int retwrite = write(fd, wrstring, sizeof(wrstring)); int retwrite = write(fd, wrstring, sizeof(wrstring));
off_t data = lseek(fd, 0L, SEEK_SET); off_t data = lseek(fd, 0L, SEEK_SET);
...@@ -80,7 +80,7 @@ void lseek_0100(void) ...@@ -80,7 +80,7 @@ void lseek_0100(void)
void lseek_0200(void) void lseek_0200(void)
{ {
char *wrstring = "This is a test sample!"; char *wrstring = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0200", 0, fd); EXPECT_STRLT("lseek_0200", 0, fd);
int retwrite = write(fd, wrstring, sizeof(wrstring)); int retwrite = write(fd, wrstring, sizeof(wrstring));
off_t data = lseek(fd, 8L, SEEK_SET); off_t data = lseek(fd, 8L, SEEK_SET);
...@@ -97,7 +97,7 @@ void lseek_0200(void) ...@@ -97,7 +97,7 @@ void lseek_0200(void)
void lseek_0300(void) void lseek_0300(void)
{ {
char *wrstring = "This is a test sample!"; char *wrstring = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0300", 0, fd); EXPECT_STRLT("lseek_0300", 0, fd);
int retwrite = write(fd, wrstring, sizeof(wrstring)); int retwrite = write(fd, wrstring, sizeof(wrstring));
off_t data = lseek(fd, 10L, SEEK_SET); off_t data = lseek(fd, 10L, SEEK_SET);
...@@ -115,7 +115,7 @@ void lseek_0300(void) ...@@ -115,7 +115,7 @@ void lseek_0300(void)
void lseek_0400(void) void lseek_0400(void)
{ {
char str[] = "This is a test sample!"; char str[] = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0400", 0, fd); EXPECT_STRLT("lseek_0400", 0, fd);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
off_t data = lseek(fd, -1L, SEEK_END); off_t data = lseek(fd, -1L, SEEK_END);
...@@ -132,7 +132,7 @@ void lseek_0400(void) ...@@ -132,7 +132,7 @@ void lseek_0400(void)
void lseek_0500(void) void lseek_0500(void)
{ {
char str[] = "This is a test sample!"; char str[] = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0500", 0, fd); EXPECT_STRLT("lseek_0500", 0, fd);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
off_t data = lseek(fd, -10L, SEEK_SET); off_t data = lseek(fd, -10L, SEEK_SET);
...@@ -149,7 +149,7 @@ void lseek_0500(void) ...@@ -149,7 +149,7 @@ void lseek_0500(void)
void lseek_0600(void) void lseek_0600(void)
{ {
char str[] = "This is a test sample!"; char str[] = "This is a test sample!";
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_STRLT("lseek_0600", 0, fd); EXPECT_STRLT("lseek_0600", 0, fd);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
off_t data = lseek(fd, 10L, SEEK_END); off_t data = lseek(fd, 10L, SEEK_END);
......
...@@ -40,7 +40,7 @@ void preadv_0100(void) ...@@ -40,7 +40,7 @@ void preadv_0100(void)
iov[1].iov_base = buf2; iov[1].iov_base = buf2;
iov[1].iov_len = sizeof(buf2) / sizeof(char); iov[1].iov_len = sizeof(buf2) / sizeof(char);
int fd = open("./preadv_function_value.c", O_RDWR | O_CREAT); int fd = open("./preadv_function_value.c", O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
EXPECT_NE("preadv_0100", fd, ERREXPECT); EXPECT_NE("preadv_0100", fd, ERREXPECT);
return; return;
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "functionalext.h" #include "functionalext.h"
#define TEST_BUFFER_SIZE 64 #define TEST_BUFFER_SIZE 64
#define TEST_MODE 0777
void rm_file(const char *name) void rm_file(const char *name)
{ {
......
...@@ -34,7 +34,7 @@ void pwritev_0100(void) ...@@ -34,7 +34,7 @@ void pwritev_0100(void)
iov[1].iov_base = buf2; iov[1].iov_base = buf2;
iov[1].iov_len = sizeof(buf2) / sizeof(char); iov[1].iov_len = sizeof(buf2) / sizeof(char);
int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT); int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT, TEST_MODE);
int count = sizeof(iov) / sizeof(struct iovec); int count = sizeof(iov) / sizeof(struct iovec);
int ret = pwritev(fd, iov, count, 0); int ret = pwritev(fd, iov, count, 0);
EXPECT_NE("pwritev_0100", ret, EOF); EXPECT_NE("pwritev_0100", ret, EOF);
...@@ -63,7 +63,7 @@ void pwritev_0200(void) ...@@ -63,7 +63,7 @@ void pwritev_0200(void)
iov[1].iov_base = buf2; iov[1].iov_base = buf2;
iov[1].iov_len = sizeof(buf2) / sizeof(char); iov[1].iov_len = sizeof(buf2) / sizeof(char);
int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT); int fd = open("pwritev_function_value.c", O_RDWR | O_CREAT, TEST_MODE);
if (fd == -1) { if (fd == -1) {
EXPECT_NE("pwritev_0200", fd, ERREXPECT); EXPECT_NE("pwritev_0200", fd, ERREXPECT);
return; return;
......
...@@ -27,7 +27,7 @@ void read_0100(void) ...@@ -27,7 +27,7 @@ void read_0100(void)
{ {
char str[] = "this is a readtest\n"; char str[] = "this is a readtest\n";
char buffer[1024] = {0}; char buffer[1024] = {0};
int fd = open("/data/readtest.txt", O_RDWR | O_CREAT); int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
EXPECT_TRUE("read_0100", fd >= 0); EXPECT_TRUE("read_0100", fd >= 0);
int retwrite = write(fd, str, sizeof(str)); int retwrite = write(fd, str, sizeof(str));
EXPECT_EQ("read_0100", retwrite, SIZE); EXPECT_EQ("read_0100", retwrite, SIZE);
......
...@@ -27,7 +27,7 @@ const char *linkfilename = "./linkfile.txt"; ...@@ -27,7 +27,7 @@ const char *linkfilename = "./linkfile.txt";
int create_file(char *path) int create_file(char *path)
{ {
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
if (fd < 0) { if (fd < 0) {
return -1; return -1;
} }
......
...@@ -30,7 +30,7 @@ void readv_0100(void) ...@@ -30,7 +30,7 @@ void readv_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
char buf1[] = "hello"; char buf1[] = "hello";
char buf2[] = "world"; char buf2[] = "world";
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
*/ */
void ttyname_r_0100(void) void ttyname_r_0100(void)
{ {
int fd = open("/data/tempfile_forttyname.txt", O_CREAT); int fd = open("/data/tempfile_forttyname.txt", O_CREAT, TEST_MODE);
char buf[128]; char buf[128];
int want = 25; int want = 25;
int result = ttyname_r(fd, buf, sizeof(buf)); int result = ttyname_r(fd, buf, sizeof(buf));
......
...@@ -28,7 +28,7 @@ void unlink_0100(void) ...@@ -28,7 +28,7 @@ void unlink_0100(void)
{ {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH("test_unlink.txt", path); FILE_ABSOLUTE_PATH("test_unlink.txt", path);
int fd = open(path, O_CREAT); int fd = open(path, O_CREAT, TEST_MODE);
int error_code = -1; int error_code = -1;
if (fd == error_code) { if (fd == error_code) {
t_error("%s unlink create file error", __func__); t_error("%s unlink create file error", __func__);
......
...@@ -189,7 +189,7 @@ void strptime_0700(void) ...@@ -189,7 +189,7 @@ void strptime_0700(void)
strptime(buffer, "%s", &tmTime); strptime(buffer, "%s", &tmTime);
second = mktime(&tmTime); second = mktime(&tmTime);
char buffResult[gBufferSize]; char buffResult[gBufferSize];
int cnt = sprintf(buffResult, "%ld", second); int cnt = sprintf(buffResult, "%lld", second);
EXPECT_TRUE("strptime_0700", cnt > 0); EXPECT_TRUE("strptime_0700", cnt > 0);
EXPECT_STREQ("strptime_0700", buffer, buffResult); EXPECT_STREQ("strptime_0700", buffer, buffResult);
} }
......
...@@ -74,7 +74,7 @@ static void dump_trace(int trace_fd) ...@@ -74,7 +74,7 @@ static void dump_trace(int trace_fd)
char buffer[READ_BUFFER_SIZE]; char buffer[READ_BUFFER_SIZE];
int nwrite; int nwrite;
int nread; int nread;
int out_fd = open(OUTFILE, O_WRONLY | O_CREAT); int out_fd = open(OUTFILE, O_WRONLY | O_CREAT, TEST_MODE);
if (out_fd == -1) { if (out_fd == -1) {
return; return;
} }
......
...@@ -146,7 +146,7 @@ template("test_unittest") { ...@@ -146,7 +146,7 @@ template("test_unittest") {
if (!defined(defines)) { if (!defined(defines)) {
defines = [] defines = []
} }
defines += [ "MUSL_FORTIFY_SOURCE=2" ] defines += [ "_FORTIFY_SOURCE=2" ]
} }
if (target_dir == "functionalext/ldso_randomization") { if (target_dir == "functionalext/ldso_randomization") {
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
__lutimes_time64; __lutimes_time64;
__lxstat; __lxstat;
__lxstat64; __lxstat64;
__memchr_diagnose; __memchr_chk;
__memcpy_chk; __memcpy_chk;
# __memmove_aarch64; # __memmove_aarch64;
__memmove_chk; __memmove_chk;
...@@ -156,14 +156,14 @@ ...@@ -156,14 +156,14 @@
__newlocale; __newlocale;
__nl_langinfo; __nl_langinfo;
__nl_langinfo_l; __nl_langinfo_l;
__open_diagnose; __open_chk;
__open64_diagnose; __open64_chk;
__openat_diagnose; __openat_chk;
__openat64_diagnose; __openat64_chk;
# __optpos; # __optpos;
__optreset; __optreset;
__overflow; __overflow;
__poll_diagnose; __poll_chk;
__posix_getopt; __posix_getopt;
__ppoll_chk; __ppoll_chk;
__ppoll_time64; __ppoll_time64;
...@@ -184,8 +184,8 @@ ...@@ -184,8 +184,8 @@
__readlink_chk; __readlink_chk;
__readlinkat_chk; __readlinkat_chk;
# __reboot; # __reboot;
__recv_diagnose; __recv_chk;
__recvfrom_diagnose; __recvfrom_chk;
__recvmmsg_time64; __recvmmsg_time64;
# __res_state; # __res_state;
__sched_cpualloc; __sched_cpualloc;
...@@ -194,8 +194,8 @@ ...@@ -194,8 +194,8 @@
__select_time64; __select_time64;
__sem_timedwait_time64; __sem_timedwait_time64;
__semtimedop_time64; __semtimedop_time64;
__send_diagnose; __send_chk;
__sendto_diagnose; __sendto_chk;
__setitimer_time64; __setitimer_time64;
__setjmp; __setjmp;
__settimeofday_time64; __settimeofday_time64;
...@@ -215,17 +215,17 @@ ...@@ -215,17 +215,17 @@
__stpncpy_chk; __stpncpy_chk;
__strcasecmp_l; __strcasecmp_l;
__strcat_chk; __strcat_chk;
__strchr_diagnose; __strchr_chk;
__strcoll_l; __strcoll_l;
__strcpy_chk; __strcpy_chk;
__strerror_l; __strerror_l;
__strlcat_diagnose; __strlcat_chk;
__strlcpy_diagnose; __strlcpy_chk;
__strlen_chk; __strlen_chk;
__strncasecmp_l; __strncasecmp_l;
__strncat_chk; __strncat_chk;
__strncpy_chk; __strncpy_chk;
__strrchr_diagnose; __strrchr_chk;
__strtod_l; __strtod_l;
__strtof_l; __strtof_l;
__strtoimax_internal; __strtoimax_internal;
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
__towupper_l; __towupper_l;
__tzname; __tzname;
__uflow; __uflow;
__umask_diagnose; __umask_chk;
__uselocale; __uselocale;
__utime64; __utime64;
__utimensat_time64; __utimensat_time64;
......
...@@ -20,6 +20,7 @@ extern "C" { ...@@ -20,6 +20,7 @@ extern "C" {
#include <bits/alltypes.h> #include <bits/alltypes.h>
#include <bits/fcntl.h> #include <bits/fcntl.h>
#include <fortify/fcntl.h>
struct flock { struct flock {
short l_type; short l_type;
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _FCNTL_H
#error "Never include this file directly; instead, include <fcntl.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
int __open_chk(const char*, int);
int __openat_chk(int, const char*, int);
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
int __open64_chk(const char*, int);
int __openat64_chk(int, const char*, int);
#endif
/*
* Even in musl FORTIFY, the following is the easiest way to call a real open.
*/
int __open_real(const char*, int, ...) __DIAGNOSE_RENAME(open);
int __openat_real(int, const char*, int, ...) __DIAGNOSE_RENAME(openat);
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
int __open64_real(const char*, int, ...) __DIAGNOSE_RENAME(open64);
int __openat64_real(int, const char*, int, ...) __DIAGNOSE_RENAME(openat64);
#endif
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
int open(const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open' " OPEN_TOO_FEW_ARGS_ERROR)
{
#ifdef __FORTIFY_RUNTIME
return __open_chk(path, flags);
#else
return __open_real(path, flags);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int open(const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags, unsigned modes)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF(!__DIAGNOSE_OPEN_MODES_USEFUL(flags) && modes, "'open' " OPEN_USELESS_MODES_WARNING)
{
return __open_real(path, flags, modes);
}
__DIAGNOSE_FORTIFY_INLINE
int openat(int dirfd, const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat' " OPEN_TOO_FEW_ARGS_ERROR)
{
#ifdef __FORTIFY_RUNTIME
return __openat_chk(dirfd, path, flags);
#else
return __openat_real(dirfd, path, flags);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int openat(int dirfd, const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags, mode_t modes)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF(!__DIAGNOSE_OPEN_MODES_USEFUL(flags) && modes, "'openat' " OPEN_USELESS_MODES_WARNING)
{
return __openat_real(dirfd, path, flags, modes);
}
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
__DIAGNOSE_FORTIFY_INLINE
int open64(const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open64' " OPEN_TOO_FEW_ARGS_ERROR)
{
#ifdef __FORTIFY_RUNTIME
return __open64_chk(path, flags);
#else
return __open64_real(path, flags);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int open64(const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags, mode_t modes)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF(!__DIAGNOSE_OPEN_MODES_USEFUL(flags) && modes, "'open64' " OPEN_USELESS_MODES_WARNING)
{
return __open64_real(path, flags, modes);
}
__DIAGNOSE_FORTIFY_INLINE
int openat64(int dirfd, const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat64' " OPEN_TOO_FEW_ARGS_ERROR)
{
#ifdef __FORTIFY_RUNTIME
return __openat64_chk(dirfd, path, flags);
#else
return __openat64_real(dirfd, path, flags);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int openat64(int dirfd, const char* const __DIAGNOSE_PASS_OBJECT_SIZE path, int flags, mode_t modes)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF(!__DIAGNOSE_OPEN_MODES_USEFUL(flags) && modes, "'openat64' " OPEN_USELESS_MODES_WARNING)
{
return __openat64_real(dirfd, path, flags, modes);
}
#endif
#endif
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _FORTIFY_FORTIFY_H
#define _FORTIFY_FORTIFY_H
#ifdef __cplusplus
extern "C" {
#endif
#if (_FORTIFY_SOURCE == 1) || (_FORTIFY_SOURCE == 2)
#ifndef __FORTIFY_COMPILATION
#define __FORTIFY_COMPILATION
#endif
#endif
#if (_FORTIFY_SOURCE == 2)
#ifndef __FORTIFY_RUNTIME
#define __FORTIFY_RUNTIME
#endif
#endif
#if defined(__cplusplus)
#define __DIAGNOSE_CAST(_k, _t, _v) (_k<_t>(_v))
#else
#define __DIAGNOSE_CAST(_k, _t, _v) ((_t) (_v))
#endif
#if defined(__LP64__)
#ifndef FORTIFY_LONG_MAX
#define FORTIFY_LONG_MAX 0x7fffffffffffffffL
#endif
#ifndef FORTIFY_SSIZE_MAX
#define FORTIFY_SSIZE_MAX FORTIFY_LONG_MAX
#endif
#else
#ifndef FORTIFY_LONG_MAX
#define FORTIFY_LONG_MAX 0x7fffffffL
#endif
#ifndef FORTIFY_SSIZE_MAX
#define FORTIFY_SSIZE_MAX FORTIFY_LONG_MAX
#endif
#endif
#ifndef FORTIFY_PATH_MAX
#define FORTIFY_PATH_MAX 4096
#endif
#define __DIAGNOSE_ALWAYS_INLINE __attribute__((__always_inline__))
#define __DIAGNOSE_PREDICT_TRUE(exp) __builtin_expect((exp) != 0, 1)
#define __DIAGNOSE_PREDICT_FALSE(exp) __builtin_expect((exp) != 0, 0)
#define __DIAGNOSE_ENABLE_IF(cond, msg) __attribute__((enable_if(cond, msg)))
#define __DIAGNOSE_ERROR_IF(cond, msg) __attribute__((diagnose_if(cond, msg, "error")))
#define __DIAGNOSE_WARNING_IF(cond, msg) __attribute__((diagnose_if(cond, msg, "warning")))
#define __DIAGNOSE_BOS_LEVEL (1)
#define __DIAGNOSE_BOSN(s, n) __builtin_object_size((s), (n))
#define __DIAGNOSE_BOS(s) __DIAGNOSE_BOSN((s), __DIAGNOSE_BOS_LEVEL)
#define __DIAGNOSE_BOS0(s) __DIAGNOSE_BOSN((s), 0)
#define __DIAGNOSE_PASS_OBJECT_SIZE_N(n) __attribute__((pass_object_size(n)))
#define __DIAGNOSE__SIZE_MUL_OVERFLOW(a, b, result) __builtin_umull_overflow(a, b, result)
#define __DIAGNOSE_PRINTFLIKE(x, y) __attribute__((__format__(printf, x, y)))
#define __DIAGNOSE_CALL_BYPASSING_FORTIFY(fn) (&(fn))
#define __DIAGNOSE_FORTIFY_INLINE static __inline__ __attribute__((no_stack_protector)) \
__DIAGNOSE_ALWAYS_INLINE
#define __DIAGNOSE_FORTIFY_VARIADIC static __inline__
#define __DIAGNOSE_PASS_OBJECT_SIZE __DIAGNOSE_PASS_OBJECT_SIZE_N(__DIAGNOSE_BOS_LEVEL)
#define __DIAGNOSE_PASS_OBJECT_SIZE0 __DIAGNOSE_PASS_OBJECT_SIZE_N(0)
#define __DIAGNOSE_FORTIFY_UNKNOWN_SIZE ((unsigned int) -1)
/* The following are intended for use in unevaluated environments, e.g. diagnose_if conditions. */
#define __DIAGNOSE_UNEVALUATED_LT(bos_val, val) \
((bos_val) != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE && (bos_val) < (val))
#define __DIAGNOSE_UNEVALUATED_LE(bos_val, val) \
((bos_val) != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE && (bos_val) <= (val))
/* The following acts in the context of evaluation. */
#define __DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND(bos_val, op, index, cond) \
((bos_val) == __DIAGNOSE_FORTIFY_UNKNOWN_SIZE || \
(__builtin_constant_p(index) && bos_val op index && (cond)))
#define __DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL(bos_val, op, index) \
__DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND(bos_val, op, index, 1)
#define __DIAGNOSE_BOS_TRIVIALLY_GE(bos_val, index) __DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL((bos_val), >=, (index))
#define __DIAGNOSE_BOS_TRIVIALLY_GT(bos_val, index) __DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL((bos_val), >, (index))
#define __DIAGNOSE_OVERLOAD __attribute__((overloadable))
/*
* A function to prevent this function from being applied.
* Used to rename the function so that the compiler emits a call to "x".
*/
#define __DIAGNOSE_RENAME(x) __asm__(#x)
#define __DIAGNOSE_OPEN_MODES_USEFUL(flags) (((flags) & O_CREAT) || ((flags) & O_TMPFILE) == O_TMPFILE)
#define __DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_val, fds, fd_count) \
__DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND((bos_val), >=, (sizeof(*(fds)) * (fd_count)), \
(fd_count) <= __DIAGNOSE_CAST(static_cast, unsigned int, -1) / sizeof(*(fds)))
#define __DIAGNOSE_UNSAFE_CHK_MUL_OVERFLOW(x, y) ((__SIZE_TYPE__)-1 / (x) < (y))
#define __DIAGNOSE_BOS_TRIVIALLY_GE_MUL(bos_val, size, count) \
__DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND(bos_val, >=, (size) * (count), \
!__DIAGNOSE_UNSAFE_CHK_MUL_OVERFLOW(size, count))
#define FORTIFY_RUNTIME_ERROR_PREFIX "Musl Fortify runtime error: "
#define OPEN_TOO_MANY_ARGS_ERROR "There are too many arguments"
#define OPEN_TOO_FEW_ARGS_ERROR "invoking with O_CREAT or O_TMPFILE, but missing pattern."
#define OPEN_USELESS_MODES_WARNING "having redundant mode bits; but missing O_CREAT."
#define CALLED_WITH_STRING_BIGGER_BUFFER "called with a string larger than the buffer"
#define FD_COUNT_LARGE_GIVEN_BUFFER "fd_count is greater than the given buffer"
#define CALLED_WITH_SIZE_BIGGER_BUFFER "called with bigger size than the buffer"
#define OUTPUT_PARAMETER_BYTES "the output parameter must be nullptr or a pointer to the buffer with >= FORTIFY_PATH_MAX bytes"
#define SIZE_LARGER_THEN_DESTINATION_BUFFER "the size is greater than the target buffer"
void __fortify_error(const char* info, ...);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _POLL_H
#error "Never include this file directly; instead, include <poll.h>"
#endif
#include <signal.h>
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
int __poll_chk(struct pollfd*, nfds_t, int, size_t);
#ifdef _GNU_SOURCE
int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t);
#endif
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
int poll(struct pollfd* const fds __DIAGNOSE_PASS_OBJECT_SIZE, nfds_t fd_amount, int timeout)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) * fd_amount),
"in call to 'poll', " FD_COUNT_LARGE_GIVEN_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos_fds = __DIAGNOSE_BOS(fds);
if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) {
return __poll_chk(fds, fd_amount, timeout, bos_fds);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_amount, timeout);
}
#ifdef _GNU_SOURCE
__DIAGNOSE_FORTIFY_INLINE
int ppoll(struct pollfd* const fds __DIAGNOSE_PASS_OBJECT_SIZE, nfds_t fd_amount,
const struct timespec* timeout, const sigset_t* mask)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) * fd_amount),
"in call to 'ppoll', " FD_COUNT_LARGE_GIVEN_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos_fds = __DIAGNOSE_BOS(fds);
if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) {
return __ppoll_chk(fds, fd_amount, timeout, mask, bos_fds);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(ppoll)(fds, fd_amount, timeout, mask);
}
#endif
#endif
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _SYS_SOCKET_H
#error "Never include this file directly; instead, include <sys/socket.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
ssize_t __sendto_chk(int, const void*, size_t, size_t, int, const struct sockaddr*,
socklen_t);
ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, struct sockaddr*,
socklen_t*);
ssize_t __send_chk(int, const void*, size_t, size_t, int);
ssize_t __recv_chk(int, void*, size_t, size_t, int);
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
ssize_t recvfrom(int fd, void* const buf __DIAGNOSE_PASS_OBJECT_SIZE0, size_t len, int flags,
struct sockaddr* src_addr, socklen_t* addr_len)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
"'recvfrom' " CALLED_WITH_SIZE_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recvfrom)(fd, buf, len, flags, src_addr, addr_len);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t sendto(int fd, const void* const buf __DIAGNOSE_PASS_OBJECT_SIZE0, size_t len, int flags,
const struct sockaddr* dest_addr, socklen_t addr_len)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
"'sendto' " CALLED_WITH_SIZE_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __sendto_chk(fd, buf, len, bos, flags, dest_addr, addr_len);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(sendto)(fd, buf, len, flags, dest_addr, addr_len);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t recv(int socket, void* const buf __DIAGNOSE_PASS_OBJECT_SIZE0, size_t len, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
"'recv' " CALLED_WITH_SIZE_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __recv_chk(socket, buf, len, bos, flags);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t send(int socket, const void* const buf __DIAGNOSE_PASS_OBJECT_SIZE0, size_t len, int flags)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
"'send' " CALLED_WITH_SIZE_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __send_chk(socket, buf, len, bos, flags);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags);
}
#endif
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _SYS_STAT_H
#error "Never include this file directly; instead, include <sys/stat.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
mode_t __umask_chk(mode_t);
mode_t __umask_real(mode_t mode) __DIAGNOSE_RENAME(umask);
#ifdef __FORTIFY_COMPILATION
/* Overload of umask. */
__DIAGNOSE_FORTIFY_INLINE
mode_t umask(mode_t mode)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ENABLE_IF(1, "")
__DIAGNOSE_ERROR_IF(mode & ~0777, "'umask' was called in invalid mode")
{
#ifdef __FORTIFY_RUNTIME
return __umask_chk(mode);
#else
return __umask_real(mode);
#endif
}
#endif
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _STDIO_H
#error "Never include this file directly; instead, include <stdio.h>"
#endif
#include <stdarg.h>
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__FORTIFY_COMPILATION)
#define FORMAT_PLACE_2 (2)
#define FORMAT_PLACE_3 (3)
#define VALIST_PLACE_0 (0)
#define VALIST_PLACE_3 (3)
#define VALIST_PLACE_4 (4)
size_t __fread_chk(void*, size_t, size_t, FILE*, size_t);
size_t __fwrite_chk(const void*, size_t, size_t, FILE*, size_t);
char* __fgets_chk(char*, int, FILE*, size_t);
__DIAGNOSE_FORTIFY_INLINE
size_t fread(void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf,
size_t size, size_t count, FILE* stream)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNSAFE_CHK_MUL_OVERFLOW(size, count),
"in call to 'fread', size * count overflows")
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), size * count),
"in call to 'fread', size * count is too large for the given buffer")
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_MUL(bos, size, count)) {
return __fread_chk(buf, size, count, stream, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(fread)(buf, size, count, stream);
}
__DIAGNOSE_FORTIFY_INLINE
size_t fwrite(const void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf,
size_t size, size_t count, FILE* stream)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNSAFE_CHK_MUL_OVERFLOW(size, count),
"in call to 'fwrite', size * count overflows")
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), size * count),
"in call to 'fwrite', size * count is too large for the given buffer")
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_MUL(bos, size, count)) {
return __fwrite_chk(buf, size, count, stream, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(fwrite)(buf, size, count, stream);
}
__DIAGNOSE_FORTIFY_INLINE
char* fgets(char* const __DIAGNOSE_PASS_OBJECT_SIZE dest, int size, FILE* stream)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(size < 0, "in call to 'fgets', size should not be less than 0")
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size),
"in call to 'fgets', " SIZE_LARGER_THEN_DESTINATION_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(dest);
if (!__DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND(bos, >=, (size_t)size, size >= 0)) {
return __fgets_chk(dest, size, stream, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(fgets)(dest, size, stream);
}
__DIAGNOSE_FORTIFY_INLINE __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_3, VALIST_PLACE_0)
int vsnprintf(char* const __DIAGNOSE_PASS_OBJECT_SIZE dest,
size_t size, const char* format, va_list ap)
__DIAGNOSE_OVERLOAD
{
size_t bos = __DIAGNOSE_BOS(dest);
return __builtin___vsnprintf_chk(dest, size, 0, bos, format, ap);
}
__DIAGNOSE_FORTIFY_INLINE __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_2, VALIST_PLACE_0)
int vsprintf(char* const __DIAGNOSE_PASS_OBJECT_SIZE dest, const char* format, va_list ap)
__DIAGNOSE_OVERLOAD
{
return __builtin___vsprintf_chk(dest, 0, __DIAGNOSE_BOS(dest), format, ap);
}
__DIAGNOSE_FORTIFY_VARIADIC __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_2, VALIST_PLACE_3)
int sprintf(char* const __DIAGNOSE_PASS_OBJECT_SIZE dest, const char* format, ...)
__DIAGNOSE_OVERLOAD
{
va_list va_l;
va_start(va_l, format);
int result = __builtin___vsprintf_chk(dest, 0, __DIAGNOSE_BOS(dest), format, va_l);
va_end(va_l);
return result;
}
__DIAGNOSE_FORTIFY_VARIADIC __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_3, VALIST_PLACE_4)
int snprintf(char* const __DIAGNOSE_PASS_OBJECT_SIZE dest, size_t size, const char* format, ...)
__DIAGNOSE_OVERLOAD
{
va_list va_l;
va_start(va_l, format);
int result = __builtin___vsnprintf_chk(dest, size, 0, __DIAGNOSE_BOS(dest), format, va_l);
va_end(va_l);
return result;
}
#endif // defined(__FORTIFY_COMPILATION)
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _STDLIB_H
#error "Never include this file directly; instead, include <stdlib.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_GNU_SOURCE) && defined(__FORTIFY_COMPILATION)
char* realpath(const char* path, char* resolved)
__DIAGNOSE_ERROR_IF(!path, "'realpath': NULL path is never correct; flipped arguments?")
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(resolved), FORTIFY_PATH_MAX),
"'realpath' " OUTPUT_PARAMETER_BYTES);
#endif
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _STRING_H
#error "Never include this file directly; instead, include <string.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
void *__memchr_chk(const void* s, int c, size_t n, size_t actual_size);
void *__memrchr_chk(const void*, int, size_t, size_t);
size_t __strlcpy_chk(char*, const char*, size_t, size_t);
size_t __strlcat_chk(char*, const char*, size_t, size_t);
char *__strchr_chk(const char* p, int ch, size_t s_len);
char *__strrchr_chk(const char *p, int ch, size_t s_len);
size_t __strlen_chk(const char* s, size_t s_len);
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
char *strcpy(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char *src)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LE(__DIAGNOSE_BOS(dest), __builtin_strlen(src)),
"'strcpy' " CALLED_WITH_STRING_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
return __builtin___strcpy_chk(dest, src, __DIAGNOSE_BOS(dest));
#else
return __builtin_strcpy(dest, src);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
char *stpcpy(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char *src)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LE(__DIAGNOSE_BOS(dest), __builtin_strlen(src)),
"'stpcpy' " CALLED_WITH_STRING_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
return __builtin___stpcpy_chk(dest, src, __DIAGNOSE_BOS(dest));
#else
return __builtin_stpcpy(dest, src);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
void *memmove(void *const dest __DIAGNOSE_PASS_OBJECT_SIZE0, const void *src, size_t len)
__DIAGNOSE_OVERLOAD
{
#ifdef __FORTIFY_RUNTIME
return __builtin___memmove_chk(dest, src, len, __DIAGNOSE_BOS(dest));
#else
return __builtin_memmove(dest, src, len);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
void *mempcpy(void *const dest __DIAGNOSE_PASS_OBJECT_SIZE, const void *src, size_t copy_amount)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(dest), copy_amount),
"'mempcpy' " CALLED_WITH_STRING_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
return __builtin___mempcpy_chk(dest, src, copy_amount, __DIAGNOSE_BOS0(dest));
#else
return __builtin_mempcpy(dest, src, copy_amount);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
char *strcat(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char *src)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LE(__DIAGNOSE_BOS(dest), __builtin_strlen(src)),
"'strcat' " CALLED_WITH_STRING_BIGGER_BUFFER)
{
#ifdef __FORTIFY_RUNTIME
return __builtin___strcat_chk(dest, src, __DIAGNOSE_BOS(dest));
#else
return __builtin_strcat(dest, src);
#endif
}
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char *strncat(char* const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char* src, size_t n)
__DIAGNOSE_OVERLOAD
{
return __builtin___strncat_chk(dest, src, n, __DIAGNOSE_BOS(dest));
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char *stpncpy(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE,
const char *const src __DIAGNOSE_PASS_OBJECT_SIZE, size_t n)
__DIAGNOSE_OVERLOAD
{
size_t bos_dest = __DIAGNOSE_BOS(dest);
return __builtin___stpncpy_chk(dest, src, n, bos_dest);
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char *strncpy(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE,
const char *const src __DIAGNOSE_PASS_OBJECT_SIZE, size_t n)
__DIAGNOSE_OVERLOAD
{
size_t bos_dest = __DIAGNOSE_BOS(dest);
return __builtin___strncpy_chk(dest, src, n, bos_dest);
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
void *memcpy(void *const dest __DIAGNOSE_PASS_OBJECT_SIZE0, const void *src, size_t copy_amount)
__DIAGNOSE_OVERLOAD
{
return __builtin___memcpy_chk(dest, src, copy_amount, __DIAGNOSE_BOS0(dest));
}
#endif
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
__DIAGNOSE_FORTIFY_INLINE
size_t strlcpy(char *const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char *src, size_t size)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size),
"'strlcpy' called with size bigger than buffer")
{
#ifdef __FORTIFY_RUNTIME
return __strlcpy_chk(dest, src, size, __DIAGNOSE_BOS(dest));
#else
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, size);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
size_t strlcat(char* const dest __DIAGNOSE_PASS_OBJECT_SIZE, const char* src, size_t size)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size),
"'strlcat' called with size bigger than buffer")
{
#ifdef __FORTIFY_RUNTIME
return __strlcat_chk(dest, src, size, __DIAGNOSE_BOS(dest));
#else
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcat)(dest, src, size);
#endif
}
#endif // defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
__DIAGNOSE_FORTIFY_INLINE
void *memset(void *const s __DIAGNOSE_PASS_OBJECT_SIZE0, int c, size_t n)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?")
{
#ifdef __FORTIFY_RUNTIME
return __builtin___memset_chk(s, c, n, __DIAGNOSE_BOS0(s));
#else
return __builtin_memset(s, c, n);
#endif
}
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
void *memchr(const void *const s __DIAGNOSE_PASS_OBJECT_SIZE, int c, size_t n)
__DIAGNOSE_OVERLOAD
{
size_t bos = __DIAGNOSE_BOS(s);
if (__DIAGNOSE_BOS_TRIVIALLY_GE(bos, n)) {
return __builtin_memchr(s, c, n);
}
return __memchr_chk(s, c, n, bos);
}
#endif // memchr __FORTIFY_RUNTIME
extern void* __memrchr_real(const void*, int, size_t) __DIAGNOSE_RENAME(memrchr);
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
void *memrchr(const void *const __DIAGNOSE_PASS_OBJECT_SIZE s, int c, size_t n)
__DIAGNOSE_OVERLOAD
{
size_t bos = __DIAGNOSE_BOS(s);
if (__DIAGNOSE_BOS_TRIVIALLY_GE(bos, n)) {
return __memrchr_real(s, c, n);
}
return __memrchr_chk(s, c, n, bos);
}
#endif
__DIAGNOSE_FORTIFY_INLINE
char* strchr(const char* const s __DIAGNOSE_PASS_OBJECT_SIZE, int c)
__DIAGNOSE_OVERLOAD
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(s);
if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) {
return __strchr_chk(s, c, bos);
}
#endif
return __builtin_strchr(s, c);
}
__DIAGNOSE_FORTIFY_INLINE
char* strrchr(const char* const s __DIAGNOSE_PASS_OBJECT_SIZE, int c)
__DIAGNOSE_OVERLOAD
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(s);
if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) {
return __strrchr_chk(s, c, bos);
}
#endif
return __builtin_strrchr(s, c);
}
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
size_t strlen(const char* const s __DIAGNOSE_PASS_OBJECT_SIZE0)
__DIAGNOSE_OVERLOAD
{
return __strlen_chk(s, __DIAGNOSE_BOS0(s));
}
#endif
#endif // __FORTIFY_COMPILATION
#ifdef __cplusplus
}
#endif
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _UNISTD_H
#error "Never include this file directly; instead, include <unistd.h>"
#endif
#include "fortify.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__FORTIFY_COMPILATION)
#define __DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(what, fn) \
__DIAGNOSE_ERROR_IF((what) > FORTIFY_SSIZE_MAX, "in call to '" #fn "', '" #what "' must be <= FORTIFY_SSIZE_MAX")
#define __DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(what, objsize, fn) \
__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT((objsize), (what)), \
"in call to '" #fn "', '" #what "' bytes overflows the given object")
#define __DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos_val, index) \
((__DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND((bos_val), >=, (index), (bos_val) <= (FORTIFY_SSIZE_MAX)) && \
__builtin_constant_p(index) && (index) <= (FORTIFY_SSIZE_MAX)))
char* __getcwd_chk(char*, size_t, size_t) ;
ssize_t __pread_chk(int, void*, size_t, off_t, size_t);
ssize_t __pread_real(int, void*, size_t, off_t) __DIAGNOSE_RENAME(pread);
ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t);
ssize_t __pwrite_real(int, const void*, size_t, off_t) __DIAGNOSE_RENAME(pwrite);
ssize_t __read_chk(int, void*, size_t, size_t);
ssize_t __write_chk(int, const void*, size_t, size_t);
ssize_t __readlink_chk(const char*, char*, size_t, size_t);
ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t);
#define __DIAGNOSE_PREAD_PREFIX(x) __pread_ ## x
#define __DIAGNOSE_PWRITE_PREFIX(x) __pwrite_ ## x
__DIAGNOSE_FORTIFY_INLINE
char* getcwd(char* const __DIAGNOSE_PASS_OBJECT_SIZE buf, size_t size)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(size, __DIAGNOSE_BOS(buf), getcwd)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, size)) {
return __getcwd_chk(buf, size, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(getcwd)(buf, size);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t pread(int fd, void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf, size_t count, off_t offset)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(count, pread)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(count, __DIAGNOSE_BOS0(buf), pread)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, count)) {
return __DIAGNOSE_PREAD_PREFIX(chk)(fd, buf, count, offset, bos);
}
#endif
return __DIAGNOSE_PREAD_PREFIX(real)(fd, buf, count, offset);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t pwrite(int fd, const void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf, size_t count, off_t offset)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(count, pwrite)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(count, __DIAGNOSE_BOS0(buf), pwrite)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, count)) {
return __DIAGNOSE_PWRITE_PREFIX(chk)(fd, buf, count, offset, bos);
}
#endif
return __DIAGNOSE_PWRITE_PREFIX(real)(fd, buf, count, offset);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t read(int fd, void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf, size_t count)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(count, read)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(count, __DIAGNOSE_BOS0(buf), read)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, count)) {
return __read_chk(fd, buf, count, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(read)(fd, buf, count);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t write(int fd, const void* const __DIAGNOSE_PASS_OBJECT_SIZE0 buf, size_t count)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(count, write)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(count, __DIAGNOSE_BOS0(buf), write)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, count)) {
return __write_chk(fd, buf, count, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(write)(fd, buf, count);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t readlink(const char* path, char* const __DIAGNOSE_PASS_OBJECT_SIZE buf, size_t size)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(size, readlink)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(size, __DIAGNOSE_BOS(buf), readlink)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, size)) {
return __readlink_chk(path, buf, size, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(readlink)(path, buf, size);
}
__DIAGNOSE_FORTIFY_INLINE
ssize_t readlinkat(int dirfd, const char* path, char* const __DIAGNOSE_PASS_OBJECT_SIZE buf, size_t size)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(size, readlinkat)
__DIAGNOSE_ERROR_IF_OVERFLOWS_OBJECTSIZE(size, __DIAGNOSE_BOS(buf), readlinkat)
{
#ifdef __FORTIFY_RUNTIME
size_t bos = __DIAGNOSE_BOS(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE_NO_OVERFLOW(bos, size)) {
return __readlinkat_chk(dirfd, path, buf, size, bos);
}
#endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(readlinkat)(dirfd, path, buf, size);
}
#endif // defined(__FORTIFY_COMPILATION)
#ifdef __cplusplus
}
#endif
\ No newline at end of file
...@@ -50,6 +50,8 @@ __REDIR(ppoll, __ppoll_time64); ...@@ -50,6 +50,8 @@ __REDIR(ppoll, __ppoll_time64);
#endif #endif
#endif #endif
#include <fortify/poll.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -212,6 +212,8 @@ typedef struct _IO_cookie_io_functions_t { ...@@ -212,6 +212,8 @@ typedef struct _IO_cookie_io_functions_t {
#define off64_t off_t #define off64_t off_t
#endif #endif
#include <fortify/stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -161,6 +161,8 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale ...@@ -161,6 +161,8 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale
#endif #endif
#endif #endif
#include <fortify/stdlib.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -96,6 +96,8 @@ char *basename(); ...@@ -96,6 +96,8 @@ char *basename();
#endif #endif
#endif #endif
#include <fortify/string.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -411,6 +411,8 @@ __REDIR(recvmmsg, __recvmmsg_time64); ...@@ -411,6 +411,8 @@ __REDIR(recvmmsg, __recvmmsg_time64);
#endif #endif
#endif #endif
#include <fortify/socket.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -118,6 +118,8 @@ __REDIR(futimens, __futimens_time64); ...@@ -118,6 +118,8 @@ __REDIR(futimens, __futimens_time64);
__REDIR(utimensat, __utimensat_time64); __REDIR(utimensat, __utimensat_time64);
#endif #endif
#include <fortify/stat.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -462,6 +462,8 @@ pid_t gettid(void); ...@@ -462,6 +462,8 @@ pid_t gettid(void);
#endif #endif
#endif #endif
#include <fortify/unistd.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -1516,5 +1516,47 @@ ...@@ -1516,5 +1516,47 @@
{ "name": "pthread_rwlock_timedwrlock_monotonic_np" }, { "name": "pthread_rwlock_timedwrlock_monotonic_np" },
{ "name": "set_application_target_sdk_version" }, { "name": "set_application_target_sdk_version" },
{ "name": "set_fatal_message" }, { "name": "set_fatal_message" },
{ "name": "tgkill" } { "name": "tgkill" },
{ "name": "__read_chk"},
{ "name": "__strncat_chk"},
{ "name": "__readlink_chk"},
{ "name": "__getcwd_chk"},
{ "name": "__fread_chk"},
{ "name": "__memmove_chk"},
{ "name": "__memset_chk"},
{ "name": "__stpncpy_chk"},
{ "name": "__mempcpy_chk"},
{ "name": "__strlen_chk"},
{ "name": "__strncpy_chk"},
{ "name": "__pread_chk"},
{ "name": "__vsnprintf_chk"},
{ "name": "__strcat_chk"},
{ "name": "__fgets_chk"},
{ "name": "__vsprintf_chk"},
{ "name": "__memcpy_chk"},
{ "name": "__fwrite_chk"},
{ "name": "__memrchr_chk"},
{ "name": "__strcpy_chk"},
{ "name": "__stpcpy_chk"},
{ "name": "__sprintf_chk"},
{ "name": "__pwrite_chk"},
{ "name": "__snprintf_chk"},
{ "name": "__readlinkat_chk"},
{ "name": "__ppoll_chk"},
{ "name": "__write_chk"},
{ "name": "__poll_chk"},
{ "name": "__strchr_chk"},
{ "name": "__sendto_chk"},
{ "name": "__umask_chk"},
{ "name": "__openat_chk"},
{ "name": "__openat64_chk"},
{ "name": "__strrchr_chk"},
{ "name": "__open64_chk"},
{ "name": "__send_chk"},
{ "name": "__memchr_chk"},
{ "name": "__strlcpy_chk"},
{ "name": "__recv_chk"},
{ "name": "__recvfrom_chk"},
{ "name": "__open_chk"},
{ "name": "__strlcat_chk"}
] ]
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
extern "C" { extern "C" {
#endif #endif
int __open_diagnose(const char*, int); int __open_chk(const char*, int);
int __openat_diagnose(int, const char*, int); int __openat_chk(int, const char*, int);
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
int __open64_diagnose(const char*, int); int __open64_chk(const char*, int);
int __openat64_diagnose(int, const char*, int); int __openat64_chk(int, const char*, int);
#endif #endif
/* /*
* Even in musl FORTIFY, the following is the easiest way to call a real open. * Even in musl FORTIFY, the following is the easiest way to call a real open.
...@@ -46,7 +46,7 @@ __DIAGNOSE_OVERLOAD ...@@ -46,7 +46,7 @@ __DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open' " OPEN_TOO_FEW_ARGS_ERROR) __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open' " OPEN_TOO_FEW_ARGS_ERROR)
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __open_diagnose(path, flags); return __open_chk(path, flags);
#else #else
return __open_real(path, flags); return __open_real(path, flags);
#endif #endif
...@@ -66,7 +66,7 @@ __DIAGNOSE_OVERLOAD ...@@ -66,7 +66,7 @@ __DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat' " OPEN_TOO_FEW_ARGS_ERROR) __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat' " OPEN_TOO_FEW_ARGS_ERROR)
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __openat_diagnose(dirfd, path, flags); return __openat_chk(dirfd, path, flags);
#else #else
return __openat_real(dirfd, path, flags); return __openat_real(dirfd, path, flags);
#endif #endif
...@@ -87,7 +87,7 @@ __DIAGNOSE_OVERLOAD ...@@ -87,7 +87,7 @@ __DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open64' " OPEN_TOO_FEW_ARGS_ERROR) __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open64' " OPEN_TOO_FEW_ARGS_ERROR)
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __open64_diagnose(path, flags); return __open64_chk(path, flags);
#else #else
return __open64_real(path, flags); return __open64_real(path, flags);
#endif #endif
...@@ -107,7 +107,7 @@ __DIAGNOSE_OVERLOAD ...@@ -107,7 +107,7 @@ __DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat64' " OPEN_TOO_FEW_ARGS_ERROR) __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat64' " OPEN_TOO_FEW_ARGS_ERROR)
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __openat64_diagnose(dirfd, path, flags); return __openat64_chk(dirfd, path, flags);
#else #else
return __openat64_real(dirfd, path, flags); return __openat64_real(dirfd, path, flags);
#endif #endif
......
...@@ -20,13 +20,13 @@ ...@@ -20,13 +20,13 @@
extern "C" { extern "C" {
#endif #endif
#if (MUSL_FORTIFY_SOURCE == 1) || (MUSL_FORTIFY_SOURCE == 2) #if (_FORTIFY_SOURCE == 1) || (_FORTIFY_SOURCE == 2)
#ifndef __FORTIFY_COMPILATION #ifndef __FORTIFY_COMPILATION
#define __FORTIFY_COMPILATION #define __FORTIFY_COMPILATION
#endif #endif
#endif #endif
#if (MUSL_FORTIFY_SOURCE == 2) #if (_FORTIFY_SOURCE == 2)
#ifndef __FORTIFY_RUNTIME #ifndef __FORTIFY_RUNTIME
#define __FORTIFY_RUNTIME #define __FORTIFY_RUNTIME
#endif #endif
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
extern "C" { extern "C" {
#endif #endif
int __poll_diagnose(struct pollfd*, nfds_t, int, size_t); int __poll_chk(struct pollfd*, nfds_t, int, size_t);
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t); int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t);
#endif #endif
...@@ -40,7 +40,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) ...@@ -40,7 +40,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds)
size_t bos_fds = __DIAGNOSE_BOS(fds); size_t bos_fds = __DIAGNOSE_BOS(fds);
if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) { if (!__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_fds, fds, fd_amount)) {
return __poll_diagnose(fds, fd_amount, timeout, bos_fds); return __poll_chk(fds, fd_amount, timeout, bos_fds);
} }
#endif #endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_amount, timeout); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_amount, timeout);
......
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
extern "C" { extern "C" {
#endif #endif
ssize_t __sendto_diagnose(int, const void*, size_t, size_t, int, const struct sockaddr*, ssize_t __sendto_chk(int, const void*, size_t, size_t, int, const struct sockaddr*,
socklen_t); socklen_t);
ssize_t __recvfrom_diagnose(int, void*, size_t, size_t, int, struct sockaddr*, ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, struct sockaddr*,
socklen_t*); socklen_t*);
ssize_t __send_diagnose(int, const void*, size_t, size_t, int); ssize_t __send_chk(int, const void*, size_t, size_t, int);
ssize_t __recv_diagnose(int, void*, size_t, size_t, int); ssize_t __recv_chk(int, void*, size_t, size_t, int);
#ifdef __FORTIFY_COMPILATION #ifdef __FORTIFY_COMPILATION
...@@ -43,7 +43,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), ...@@ -43,7 +43,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
size_t bos = __DIAGNOSE_BOS0(buf); size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __recvfrom_diagnose(fd, buf, len, bos, flags, src_addr, addr_len); return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
} }
#endif #endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recvfrom)(fd, buf, len, flags, src_addr, addr_len); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recvfrom)(fd, buf, len, flags, src_addr, addr_len);
...@@ -60,7 +60,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), ...@@ -60,7 +60,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
size_t bos = __DIAGNOSE_BOS0(buf); size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __sendto_diagnose(fd, buf, len, bos, flags, dest_addr, addr_len); return __sendto_chk(fd, buf, len, bos, flags, dest_addr, addr_len);
} }
#endif #endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(sendto)(fd, buf, len, flags, dest_addr, addr_len); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(sendto)(fd, buf, len, flags, dest_addr, addr_len);
...@@ -76,7 +76,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), ...@@ -76,7 +76,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
size_t bos = __DIAGNOSE_BOS0(buf); size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __recv_diagnose(socket, buf, len, bos, flags); return __recv_chk(socket, buf, len, bos, flags);
} }
#endif #endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags);
...@@ -92,7 +92,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), ...@@ -92,7 +92,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len),
size_t bos = __DIAGNOSE_BOS0(buf); size_t bos = __DIAGNOSE_BOS0(buf);
if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) {
return __send_diagnose(socket, buf, len, bos, flags); return __send_chk(socket, buf, len, bos, flags);
} }
#endif #endif
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags);
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
extern "C" { extern "C" {
#endif #endif
mode_t __umask_diagnose(mode_t); mode_t __umask_chk(mode_t);
mode_t __umask_real(mode_t mode) __DIAGNOSE_RENAME(umask); mode_t __umask_real(mode_t mode) __DIAGNOSE_RENAME(umask);
#ifdef __FORTIFY_COMPILATION #ifdef __FORTIFY_COMPILATION
...@@ -35,7 +35,7 @@ __DIAGNOSE_ENABLE_IF(1, "") ...@@ -35,7 +35,7 @@ __DIAGNOSE_ENABLE_IF(1, "")
__DIAGNOSE_ERROR_IF(mode & ~0777, "'umask' was called in invalid mode") __DIAGNOSE_ERROR_IF(mode & ~0777, "'umask' was called in invalid mode")
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __umask_diagnose(mode); return __umask_chk(mode);
#else #else
return __umask_real(mode); return __umask_real(mode);
#endif #endif
......
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
extern "C" { extern "C" {
#endif #endif
void *__memchr_diagnose(const void* s, int c, size_t n, size_t actual_size); void *__memchr_chk(const void* s, int c, size_t n, size_t actual_size);
void *__memrchr_chk(const void*, int, size_t, size_t); void *__memrchr_chk(const void*, int, size_t, size_t);
size_t __strlcpy_diagnose(char*, const char*, size_t, size_t); size_t __strlcpy_chk(char*, const char*, size_t, size_t);
size_t __strlcat_diagnose(char*, const char*, size_t, size_t); size_t __strlcat_chk(char*, const char*, size_t, size_t);
char *__strchr_diagnose(const char* p, int ch, size_t s_len); char *__strchr_chk(const char* p, int ch, size_t s_len);
char *__strrchr_diagnose(const char *p, int ch, size_t s_len); char *__strrchr_chk(const char *p, int ch, size_t s_len);
size_t __strlen_chk(const char* s, size_t s_len); size_t __strlen_chk(const char* s, size_t s_len);
#ifdef __FORTIFY_COMPILATION #ifdef __FORTIFY_COMPILATION
...@@ -143,7 +143,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size), ...@@ -143,7 +143,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size),
"'strlcpy' called with size bigger than buffer") "'strlcpy' called with size bigger than buffer")
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __strlcpy_diagnose(dest, src, size, __DIAGNOSE_BOS(dest)); return __strlcpy_chk(dest, src, size, __DIAGNOSE_BOS(dest));
#else #else
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, size); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, size);
#endif #endif
...@@ -156,7 +156,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size), ...@@ -156,7 +156,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size),
"'strlcat' called with size bigger than buffer") "'strlcat' called with size bigger than buffer")
{ {
#ifdef __FORTIFY_RUNTIME #ifdef __FORTIFY_RUNTIME
return __strlcat_diagnose(dest, src, size, __DIAGNOSE_BOS(dest)); return __strlcat_chk(dest, src, size, __DIAGNOSE_BOS(dest));
#else #else
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcat)(dest, src, size); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcat)(dest, src, size);
#endif #endif
...@@ -184,7 +184,7 @@ __DIAGNOSE_OVERLOAD ...@@ -184,7 +184,7 @@ __DIAGNOSE_OVERLOAD
if (__DIAGNOSE_BOS_TRIVIALLY_GE(bos, n)) { if (__DIAGNOSE_BOS_TRIVIALLY_GE(bos, n)) {
return __builtin_memchr(s, c, n); return __builtin_memchr(s, c, n);
} }
return __memchr_diagnose(s, c, n, bos); return __memchr_chk(s, c, n, bos);
} }
#endif // memchr __FORTIFY_RUNTIME #endif // memchr __FORTIFY_RUNTIME
...@@ -211,7 +211,7 @@ __DIAGNOSE_OVERLOAD ...@@ -211,7 +211,7 @@ __DIAGNOSE_OVERLOAD
size_t bos = __DIAGNOSE_BOS(s); size_t bos = __DIAGNOSE_BOS(s);
if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) { if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) {
return __strchr_diagnose(s, c, bos); return __strchr_chk(s, c, bos);
} }
#endif #endif
return __builtin_strchr(s, c); return __builtin_strchr(s, c);
...@@ -225,7 +225,7 @@ __DIAGNOSE_OVERLOAD ...@@ -225,7 +225,7 @@ __DIAGNOSE_OVERLOAD
size_t bos = __DIAGNOSE_BOS(s); size_t bos = __DIAGNOSE_BOS(s);
if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) { if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) {
return __strrchr_diagnose(s, c, bos); return __strrchr_chk(s, c, bos);
} }
#endif #endif
return __builtin_strrchr(s, c); return __builtin_strrchr(s, c);
......
...@@ -57,7 +57,7 @@ static inline bool __needs_mode(int flags) ...@@ -57,7 +57,7 @@ static inline bool __needs_mode(int flags)
return ((flags & O_CREAT) == O_CREAT) || ((flags & O_TMPFILE) == O_TMPFILE); return ((flags & O_CREAT) == O_CREAT) || ((flags & O_TMPFILE) == O_TMPFILE);
} }
int __open_diagnose(const char* pathname, int flags) int __open_chk(const char* pathname, int flags)
{ {
if (__needs_mode(flags)) { if (__needs_mode(flags)) {
__fortify_error("open: " OPEN_TOO_FEW_ARGS_ERROR); __fortify_error("open: " OPEN_TOO_FEW_ARGS_ERROR);
...@@ -65,7 +65,7 @@ int __open_diagnose(const char* pathname, int flags) ...@@ -65,7 +65,7 @@ int __open_diagnose(const char* pathname, int flags)
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(open)(pathname, __force_O_LARGEFILE(flags), 0); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(open)(pathname, __force_O_LARGEFILE(flags), 0);
} }
int __openat_diagnose(int fd, const char* pathname, int flags) int __openat_chk(int fd, const char* pathname, int flags)
{ {
if (__needs_mode(flags)) { if (__needs_mode(flags)) {
__fortify_error("openat: " OPEN_TOO_FEW_ARGS_ERROR); __fortify_error("openat: " OPEN_TOO_FEW_ARGS_ERROR);
...@@ -74,7 +74,7 @@ int __openat_diagnose(int fd, const char* pathname, int flags) ...@@ -74,7 +74,7 @@ int __openat_diagnose(int fd, const char* pathname, int flags)
} }
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
int __open64_diagnose(const char* pathname, int flags) int __open64_chk(const char* pathname, int flags)
{ {
if (__needs_mode(flags)) { if (__needs_mode(flags)) {
__fortify_error("open64: " OPEN_TOO_FEW_ARGS_ERROR); __fortify_error("open64: " OPEN_TOO_FEW_ARGS_ERROR);
...@@ -82,7 +82,7 @@ int __open64_diagnose(const char* pathname, int flags) ...@@ -82,7 +82,7 @@ int __open64_diagnose(const char* pathname, int flags)
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(open64)(pathname, __force_O_LARGEFILE(flags), 0); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(open64)(pathname, __force_O_LARGEFILE(flags), 0);
} }
int __openat64_diagnose(int fd, const char* pathname, int flags) int __openat64_chk(int fd, const char* pathname, int flags)
{ {
if (__needs_mode(flags)) { if (__needs_mode(flags)) {
__fortify_error("openat64: " OPEN_TOO_FEW_ARGS_ERROR); __fortify_error("openat64: " OPEN_TOO_FEW_ARGS_ERROR);
...@@ -100,7 +100,7 @@ static inline void __diagnose_pollfd_array(const char* fn, size_t fds_size, nfds ...@@ -100,7 +100,7 @@ static inline void __diagnose_pollfd_array(const char* fn, size_t fds_size, nfds
} }
} }
int __poll_diagnose(struct pollfd* fds, nfds_t fd_count, int timeout, size_t fds_size) int __poll_chk(struct pollfd* fds, nfds_t fd_count, int timeout, size_t fds_size)
{ {
__diagnose_pollfd_array("poll", fds_size, fd_count); __diagnose_pollfd_array("poll", fds_size, fd_count);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_count, timeout); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_count, timeout);
...@@ -123,33 +123,33 @@ static inline void __diagnose_buffer_access(const char* fn, const char* action, ...@@ -123,33 +123,33 @@ static inline void __diagnose_buffer_access(const char* fn, const char* action,
} }
} }
ssize_t __recvfrom_diagnose(int socket, void* buf, size_t len, size_t buf_size, ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buf_size,
int flags, struct sockaddr* src_addr, socklen_t* addrlen) int flags, struct sockaddr* src_addr, socklen_t* addrlen)
{ {
__diagnose_buffer_access("recvfrom", "write into", len, buf_size); __diagnose_buffer_access("recvfrom", "write into", len, buf_size);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recvfrom)(socket, buf, len, flags, src_addr, addrlen); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recvfrom)(socket, buf, len, flags, src_addr, addrlen);
} }
ssize_t __sendto_diagnose(int socket, const void* buf, size_t len, size_t buflen, ssize_t __sendto_chk(int socket, const void* buf, size_t len, size_t buflen,
int flags, const struct sockaddr* dest_addr, socklen_t addrlen) int flags, const struct sockaddr* dest_addr, socklen_t addrlen)
{ {
__diagnose_buffer_access("sendto", "read from", len, buflen); __diagnose_buffer_access("sendto", "read from", len, buflen);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(sendto)(socket, buf, len, flags, dest_addr, addrlen); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(sendto)(socket, buf, len, flags, dest_addr, addrlen);
} }
ssize_t __recv_diagnose(int socket, void* buf, size_t len, size_t buf_size, int flags) ssize_t __recv_chk(int socket, void* buf, size_t len, size_t buf_size, int flags)
{ {
__diagnose_buffer_access("recv", "write into", len, buf_size); __diagnose_buffer_access("recv", "write into", len, buf_size);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags);
} }
ssize_t __send_diagnose(int socket, const void* buf, size_t len, size_t buflen, int flags) ssize_t __send_chk(int socket, const void* buf, size_t len, size_t buflen, int flags)
{ {
__diagnose_buffer_access("send", "read from", len, buflen); __diagnose_buffer_access("send", "read from", len, buflen);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags);
} }
mode_t __umask_diagnose(mode_t mode) mode_t __umask_chk(mode_t mode)
{ {
if (__DIAGNOSE_PREDICT_FALSE((mode & FILE_MODE_ALL) != mode)) { if (__DIAGNOSE_PREDICT_FALSE((mode & FILE_MODE_ALL) != mode)) {
__fortify_error("umask: called with invalid mask %o\n", mode); __fortify_error("umask: called with invalid mask %o\n", mode);
...@@ -225,7 +225,7 @@ char* __stpcpy_chk(char* dest, const char* src, size_t dst_len) ...@@ -225,7 +225,7 @@ char* __stpcpy_chk(char* dest, const char* src, size_t dst_len)
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(stpcpy)(dest, src); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(stpcpy)(dest, src);
} }
void* __memchr_diagnose(const void* s, int c, size_t n, size_t actual_size) void* __memchr_chk(const void* s, int c, size_t n, size_t actual_size)
{ {
__diagnose_buffer_access("memchr", "read from", n, actual_size); __diagnose_buffer_access("memchr", "read from", n, actual_size);
void* const_cast_s = s; void* const_cast_s = s;
...@@ -241,17 +241,6 @@ char* __stpncpy_chk(char* dest, const char* src, size_t len, size_t dst_len) ...@@ -241,17 +241,6 @@ char* __stpncpy_chk(char* dest, const char* src, size_t len, size_t dst_len)
char *__strncpy_chk(char *dest, const char *src, size_t len, size_t dst_len) char *__strncpy_chk(char *dest, const char *src, size_t len, size_t dst_len)
{ {
__diagnose_buffer_access("strncpy", "write into", len, dst_len); __diagnose_buffer_access("strncpy", "write into", len, dst_len);
if (len != 0) {
char *d = dest;
const char *s = src;
size_t src_len = strlen(src);
do {
size_t s_copy_len = (size_t)(s - src);
if (__DIAGNOSE_PREDICT_FALSE(s_copy_len >= src_len)) {
__fortify_error("strncpy: diagnose read exceed end of %zu-byte buffer\n", src_len);
}
} while (--len != 0);
}
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strncpy)(dest, src, len); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strncpy)(dest, src, len);
} }
...@@ -263,14 +252,14 @@ void *__memset_chk(void *dest, int byte, size_t count, size_t dst_len) ...@@ -263,14 +252,14 @@ void *__memset_chk(void *dest, int byte, size_t count, size_t dst_len)
} }
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
size_t __strlcpy_diagnose(char *dest, const char *src, size_t __strlcpy_chk(char *dest, const char *src,
size_t supplied_size, size_t dst_len_from_compiler) size_t supplied_size, size_t dst_len_from_compiler)
{ {
__diagnose_buffer_access("strlcpy", "write into", supplied_size, dst_len_from_compiler); __diagnose_buffer_access("strlcpy", "write into", supplied_size, dst_len_from_compiler);
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, supplied_size); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, supplied_size);
} }
size_t __strlcat_diagnose(char *dest, const char *src, size_t __strlcat_chk(char *dest, const char *src,
size_t supplied_size, size_t dst_len_from_compiler) size_t supplied_size, size_t dst_len_from_compiler)
{ {
__diagnose_buffer_access("strlcat", "write into", supplied_size, dst_len_from_compiler); __diagnose_buffer_access("strlcat", "write into", supplied_size, dst_len_from_compiler);
...@@ -278,7 +267,7 @@ size_t __strlcat_diagnose(char *dest, const char *src, ...@@ -278,7 +267,7 @@ size_t __strlcat_diagnose(char *dest, const char *src,
} }
#endif #endif
char* __strchr_diagnose(const char *s, int c, size_t s_len) char* __strchr_chk(const char *s, int c, size_t s_len)
{ {
if (s_len == 0) { if (s_len == 0) {
__fortify_error("strchr: avoid read exceed end of buffer\n"); __fortify_error("strchr: avoid read exceed end of buffer\n");
...@@ -286,7 +275,7 @@ char* __strchr_diagnose(const char *s, int c, size_t s_len) ...@@ -286,7 +275,7 @@ char* __strchr_diagnose(const char *s, int c, size_t s_len)
return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strchr)(s, c); return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strchr)(s, c);
} }
char *__strrchr_diagnose(const char *s, int c, size_t s_len) char *__strrchr_chk(const char *s, int c, size_t s_len)
{ {
if (s_len == 0) { if (s_len == 0) {
__fortify_error("strrchr: avoid read exceed end of buffer\n"); __fortify_error("strrchr: avoid read exceed end of buffer\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册