From 11af135f04e180e2cd156ac8e2e0bad786f2cb75 Mon Sep 17 00:00:00 2001 From: haotuo <380743811@qq.com> Date: Thu, 4 May 2023 22:01:28 +0800 Subject: [PATCH] 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: haotuo Change-Id: If4d2dd64284d432dcc8dd3d8de9fd7f198a27e82 --- libc-test/src/common/test.h | 2 + .../src/functionalext/supplement/fcntl/open.c | 10 +- .../functionalext/supplement/fcntl/openat.c | 13 +- .../functionalext/supplement/ipc/semtimedop.c | 2 +- .../supplement/legacy/getpagesize.c | 2 +- .../supplement/linux/copy_file_range.c | 9 +- .../supplement/linux/fallocate.c | 6 +- .../supplement/linux/fgetxattr.c | 2 +- .../functionalext/supplement/linux/flock.c | 12 +- .../functionalext/supplement/linux/getxattr.c | 2 +- .../supplement/linux/lremovexattr.c | 2 +- .../supplement/linux/lsetxattr.c | 2 +- .../supplement/linux/remap_file_pages.c | 2 +- .../supplement/linux/removexattr.c | 2 +- .../functionalext/supplement/linux/sendfile.c | 2 +- .../functionalext/supplement/linux/setxattr.c | 2 +- .../functionalext/supplement/linux/splice.c | 4 +- .../supplement/linux/sync_file_range.c | 6 +- .../functionalext/supplement/linux/syncfs.c | 2 +- .../supplement/manual/unistd/isatty.c | 2 +- .../src/functionalext/supplement/misc/lockf.c | 8 +- .../src/functionalext/supplement/misc/pty.c | 13 +- .../functionalext/supplement/misc/realpath.c | 4 +- .../functionalext/supplement/mman/madvise.c | 2 +- .../supplement/mman/posix_madvise.c | 2 +- .../supplement/process/fexecve.c | 2 +- .../supplement/select/poll_sup.c | 24 +- .../src/functionalext/supplement/stat/chmod.c | 4 +- .../functionalext/supplement/stat/fchmod.c | 4 +- .../functionalext/supplement/stat/fchmodat.c | 4 +- .../functionalext/supplement/stat/fstatat.c | 8 +- .../src/functionalext/supplement/stat/mknod.c | 2 - .../functionalext/supplement/stat/utimensat.c | 4 +- .../functionalext/supplement/stdio/dprintf.c | 4 +- .../functionalext/supplement/stdio/fgetws.c | 2 +- .../functionalext/supplement/stdio/getchar.c | 2 +- .../supplement/stdio/getchar_unlocked.c | 2 +- .../functionalext/supplement/stdio/rename.c | 6 +- .../functionalext/supplement/stdio/vdprintf.c | 2 +- .../functionalext/supplement/unistd/dup3.c | 4 +- .../supplement/unistd/faccessat.c | 8 +- .../functionalext/supplement/unistd/fchown.c | 10 +- .../supplement/unistd/fchownat.c | 4 +- .../supplement/unistd/fdatasync.c | 4 +- .../functionalext/supplement/unistd/fsync.c | 2 +- .../functionalext/supplement/unistd/lseek.c | 14 +- .../functionalext/supplement/unistd/preadv.c | 2 +- .../functionalext/supplement/unistd/pwrite.c | 1 - .../functionalext/supplement/unistd/pwritev.c | 4 +- .../functionalext/supplement/unistd/read.c | 2 +- .../supplement/unistd/readlinkat.c | 2 +- .../functionalext/supplement/unistd/readv.c | 2 +- .../supplement/unistd/ttyname_r.c | 2 +- .../functionalext/supplement/unistd/unlink.c | 2 +- .../src/functionalext/time/strptime_ext.c | 2 +- .../src/functionalext/trace/trace_marker.c | 2 +- libc-test/test_template.gni | 2 +- libc.map.txt | 30 +-- ndk_musl_include/fcntl.h | 1 + ndk_musl_include/fortify/fcntl.h | 129 +++++++++ ndk_musl_include/fortify/fortify.h | 137 ++++++++++ ndk_musl_include/fortify/poll.h | 72 +++++ ndk_musl_include/fortify/socket.h | 104 ++++++++ ndk_musl_include/fortify/stat.h | 47 ++++ ndk_musl_include/fortify/stdio.h | 136 ++++++++++ ndk_musl_include/fortify/stdlib.h | 34 +++ ndk_musl_include/fortify/string.h | 246 ++++++++++++++++++ ndk_musl_include/fortify/unistd.h | 171 ++++++++++++ ndk_musl_include/poll.h | 2 + ndk_musl_include/stdio.h | 2 + ndk_musl_include/stdlib.h | 2 + ndk_musl_include/string.h | 2 + ndk_musl_include/sys/socket.h | 2 + ndk_musl_include/sys/stat.h | 2 + ndk_musl_include/unistd.h | 2 + ndk_script/adapter/libc.ndk.json | 44 +++- porting/linux/user/include/fortify/fcntl.h | 16 +- porting/linux/user/include/fortify/fortify.h | 4 +- porting/linux/user/include/fortify/poll.h | 4 +- porting/linux/user/include/fortify/socket.h | 16 +- porting/linux/user/include/fortify/stat.h | 4 +- porting/linux/user/include/fortify/string.h | 20 +- porting/linux/user/src/fortify/fortify.c | 41 ++- 83 files changed, 1311 insertions(+), 213 deletions(-) create mode 100644 ndk_musl_include/fortify/fcntl.h create mode 100644 ndk_musl_include/fortify/fortify.h create mode 100644 ndk_musl_include/fortify/poll.h create mode 100644 ndk_musl_include/fortify/socket.h create mode 100644 ndk_musl_include/fortify/stat.h create mode 100644 ndk_musl_include/fortify/stdio.h create mode 100644 ndk_musl_include/fortify/stdlib.h create mode 100644 ndk_musl_include/fortify/string.h create mode 100644 ndk_musl_include/fortify/unistd.h diff --git a/libc-test/src/common/test.h b/libc-test/src/common/test.h index f2f415a72..dd5893473 100644 --- a/libc-test/src/common/test.h +++ b/libc-test/src/common/test.h @@ -85,3 +85,5 @@ int t_setutf8(void); #define __utimes_time64 utimes #define __wait4_time64 wait4 #endif + +#define TEST_MODE 0666 diff --git a/libc-test/src/functionalext/supplement/fcntl/open.c b/libc-test/src/functionalext/supplement/fcntl/open.c index ccca1ec82..186a3a870 100755 --- a/libc-test/src/functionalext/supplement/fcntl/open.c +++ b/libc-test/src/functionalext/supplement/fcntl/open.c @@ -29,7 +29,7 @@ void open_0100(void) { char s[] = "test"; 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)); ssize_t size = read(fd, buffer, sizeof(buffer)); EXPECT_EQ("open_0100", fd, 4); @@ -60,7 +60,7 @@ void open_0300(void) { char s[] = "test"; 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)); EXPECT_EQ("open_0300", fd, 4); EXPECT_STREQ("open_0300", buffer, ""); @@ -90,7 +90,7 @@ void open_0500(void) { char s[] = "test"; 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)); EXPECT_EQ("open_0500", fd, 4); EXPECT_STREQ("open_0500", buffer, ""); @@ -138,7 +138,7 @@ void open_0800(void) { char s[] = "test"; 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)); EXPECT_EQ("open_0800", fd, 4); EXPECT_STREQ("open_0800", buffer, ""); @@ -157,7 +157,7 @@ void open_0900(void) { char s[] = "test"; 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)); EXPECT_EQ("open_0900", fd, 4); EXPECT_STREQ("open_0900", buffer, ""); diff --git a/libc-test/src/functionalext/supplement/fcntl/openat.c b/libc-test/src/functionalext/supplement/fcntl/openat.c index 4c63908b6..73de82492 100755 --- a/libc-test/src/functionalext/supplement/fcntl/openat.c +++ b/libc-test/src/functionalext/supplement/fcntl/openat.c @@ -17,7 +17,6 @@ #include #include "functionalext.h" -#define TEST_MODE 0666 /** * @tc.name : openat_0100 * @tc.desc : Open /dev/null @@ -25,13 +24,13 @@ */ 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); - ret = openat(0, "/dev/null", O_TMPFILE); + ret = openat(0, "/dev/null", O_TMPFILE, TEST_MODE); 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); } @@ -42,13 +41,13 @@ void openat_0100(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); - ret = openat(0, "openat_test", O_TMPFILE); + ret = openat(0, "openat_test", O_TMPFILE, TEST_MODE); 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); } diff --git a/libc-test/src/functionalext/supplement/ipc/semtimedop.c b/libc-test/src/functionalext/supplement/ipc/semtimedop.c index dca870d64..15be91749 100644 --- a/libc-test/src/functionalext/supplement/ipc/semtimedop.c +++ b/libc-test/src/functionalext/supplement/ipc/semtimedop.c @@ -31,7 +31,7 @@ void semtimedop_0100(void) { char path[PATH_MAX] = {0}; 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) { t_error("%s failed: fd = %d\n", __func__, fd); } diff --git a/libc-test/src/functionalext/supplement/legacy/getpagesize.c b/libc-test/src/functionalext/supplement/legacy/getpagesize.c index e94b22432..747e8fb42 100644 --- a/libc-test/src/functionalext/supplement/legacy/getpagesize.c +++ b/libc-test/src/functionalext/supplement/legacy/getpagesize.c @@ -29,7 +29,7 @@ void getpagesize_0100() system("getconf PAGE_SIZE > /data/1.txt"); FILE *fd; 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)); remove("/data/1.txt"); } diff --git a/libc-test/src/functionalext/supplement/linux/copy_file_range.c b/libc-test/src/functionalext/supplement/linux/copy_file_range.c index 8f28c563d..7d6e4b6da 100644 --- a/libc-test/src/functionalext/supplement/linux/copy_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/copy_file_range.c @@ -20,7 +20,6 @@ #include "filepath_util.h" const char *str = "Hello"; - /** * @tc.name : copy_file_range_0100 * @tc.desc : Copy a range of data from one file to another @@ -36,7 +35,7 @@ void copy_file_range_0100(void) FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); 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) { t_error("%s open path_in failed\n", __func__); return; @@ -51,7 +50,7 @@ void copy_file_range_0100(void) close(fd_in); 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) { t_error("%s open path_out failed\n", __func__); return; @@ -115,7 +114,7 @@ void copy_file_range_0300(void) FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); 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) { t_error("%s open path_in failed\n", __func__); return; @@ -130,7 +129,7 @@ void copy_file_range_0300(void) close(fd_in); 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) { t_error("%s open path_out failed\n", __func__); return; diff --git a/libc-test/src/functionalext/supplement/linux/fallocate.c b/libc-test/src/functionalext/supplement/linux/fallocate.c index 1558a9e78..10a47516f 100755 --- a/libc-test/src/functionalext/supplement/linux/fallocate.c +++ b/libc-test/src/functionalext/supplement/linux/fallocate.c @@ -29,7 +29,7 @@ void fallocate_0100() { char str[] = "this is a fatest\n"; 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); int retwrite = write(fd, str, sizeof(str)); EXPECT_EQ("fallocate_0100", retwrite, SIZE); @@ -48,7 +48,7 @@ void fallocate_0200(void) { char str[] = "this is a fatest\n"; 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); int retwrite = write(fd, str, sizeof(str)); EXPECT_EQ("fallocate_0200", retwrite, SIZE); @@ -67,7 +67,7 @@ void fallocate_0300(void) { char str[] = "this is a fatest\n"; 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); int retwrite = write(fd, str, sizeof(str)); EXPECT_EQ("fallocate_0300", retwrite, SIZE); diff --git a/libc-test/src/functionalext/supplement/linux/fgetxattr.c b/libc-test/src/functionalext/supplement/linux/fgetxattr.c index 30ed851bb..536256507 100644 --- a/libc-test/src/functionalext/supplement/linux/fgetxattr.c +++ b/libc-test/src/functionalext/supplement/linux/fgetxattr.c @@ -30,7 +30,7 @@ void fgetxattr_0100(void) char name[] = "user.x"; 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) { t_error("%s open failed\n", __func__); } diff --git a/libc-test/src/functionalext/supplement/linux/flock.c b/libc-test/src/functionalext/supplement/linux/flock.c index 76b775544..53d678377 100644 --- a/libc-test/src/functionalext/supplement/linux/flock.c +++ b/libc-test/src/functionalext/supplement/linux/flock.c @@ -25,7 +25,7 @@ void flock_0100(void) { 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); lseek(fd, 2, SEEK_SET); @@ -43,7 +43,7 @@ void flock_0100(void) void flock_0200(void) { 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); lseek(fd, 2, SEEK_SET); @@ -61,7 +61,7 @@ void flock_0200(void) void flock_0300(void) { 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); lseek(fd, 2, SEEK_SET); @@ -79,7 +79,7 @@ void flock_0300(void) void flock_0400(void) { 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); lseek(fd, 2, SEEK_SET); @@ -97,7 +97,7 @@ void flock_0400(void) void flock_0500(void) { 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); lseek(fd, 2, SEEK_SET); @@ -126,7 +126,7 @@ void flock_0600(void) void flock_0700() { 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); lseek(fd, 2, SEEK_SET); diff --git a/libc-test/src/functionalext/supplement/linux/getxattr.c b/libc-test/src/functionalext/supplement/linux/getxattr.c index 82600f0df..61b8091aa 100644 --- a/libc-test/src/functionalext/supplement/linux/getxattr.c +++ b/libc-test/src/functionalext/supplement/linux/getxattr.c @@ -29,7 +29,7 @@ const int size = 3; */ 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) { t_error("%s failed: fd = %d\n", __func__, fd); return; diff --git a/libc-test/src/functionalext/supplement/linux/lremovexattr.c b/libc-test/src/functionalext/supplement/linux/lremovexattr.c index 3db2f66bc..40a823eb2 100644 --- a/libc-test/src/functionalext/supplement/linux/lremovexattr.c +++ b/libc-test/src/functionalext/supplement/linux/lremovexattr.c @@ -29,7 +29,7 @@ const int size = 3; */ 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) { t_error("%s failed: fd = %d\n", __func__, fd); return; diff --git a/libc-test/src/functionalext/supplement/linux/lsetxattr.c b/libc-test/src/functionalext/supplement/linux/lsetxattr.c index 0626cd00b..6baafdeaa 100644 --- a/libc-test/src/functionalext/supplement/linux/lsetxattr.c +++ b/libc-test/src/functionalext/supplement/linux/lsetxattr.c @@ -29,7 +29,7 @@ const int size = 3; */ 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) { t_error("%s failed: fd = %d\n", __func__, fd); return; diff --git a/libc-test/src/functionalext/supplement/linux/remap_file_pages.c b/libc-test/src/functionalext/supplement/linux/remap_file_pages.c index 1dfff4dde..23d471257 100755 --- a/libc-test/src/functionalext/supplement/linux/remap_file_pages.c +++ b/libc-test/src/functionalext/supplement/linux/remap_file_pages.c @@ -104,7 +104,7 @@ void remap_file_pages_0100(void) { 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) { t_error("%s open failed\n", __func__); } diff --git a/libc-test/src/functionalext/supplement/linux/removexattr.c b/libc-test/src/functionalext/supplement/linux/removexattr.c index 71e92991a..5fd46d615 100644 --- a/libc-test/src/functionalext/supplement/linux/removexattr.c +++ b/libc-test/src/functionalext/supplement/linux/removexattr.c @@ -33,7 +33,7 @@ void removexattr_0100(void) { char path[PATH_MAX] = {0}; 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) { t_error("%s failed: fd = %d\n", __func__, fd); } diff --git a/libc-test/src/functionalext/supplement/linux/sendfile.c b/libc-test/src/functionalext/supplement/linux/sendfile.c index 017934ad8..8433b6256 100644 --- a/libc-test/src/functionalext/supplement/linux/sendfile.c +++ b/libc-test/src/functionalext/supplement/linux/sendfile.c @@ -46,7 +46,7 @@ void sendfile_0100(void) 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) { t_error("%s failed: open. tofd = %d\n", __func__, tofd); } diff --git a/libc-test/src/functionalext/supplement/linux/setxattr.c b/libc-test/src/functionalext/supplement/linux/setxattr.c index 60981eec6..e2704070a 100644 --- a/libc-test/src/functionalext/supplement/linux/setxattr.c +++ b/libc-test/src/functionalext/supplement/linux/setxattr.c @@ -33,7 +33,7 @@ void setxattr_0100(void) { char path[PATH_MAX] = {0}; 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) { t_error("%s failed: fd = %d\n", __func__, fd); } diff --git a/libc-test/src/functionalext/supplement/linux/splice.c b/libc-test/src/functionalext/supplement/linux/splice.c index ef00033aa..6cfc1ccf1 100644 --- a/libc-test/src/functionalext/supplement/linux/splice.c +++ b/libc-test/src/functionalext/supplement/linux/splice.c @@ -35,12 +35,12 @@ void splice_0100(void) FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); 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) { 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) { t_error("%s failed: tofd = %d\n", __func__, tofd); } diff --git a/libc-test/src/functionalext/supplement/linux/sync_file_range.c b/libc-test/src/functionalext/supplement/linux/sync_file_range.c index 824a9975b..dd628579f 100644 --- a/libc-test/src/functionalext/supplement/linux/sync_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/sync_file_range.c @@ -32,7 +32,7 @@ void sync_file_range_0100(void) char path[PATH_MAX] = {0}; 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) { t_error("%s open failed\n", __func__); return; @@ -77,7 +77,7 @@ void sync_file_range_0300(void) char path[PATH_MAX] = {0}; 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) { t_error("%s open failed\n", __func__); return; @@ -106,7 +106,7 @@ void sync_file_range_0400(void) char path[PATH_MAX] = {0}; 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) { t_error("%s open failed\n", __func__); return; diff --git a/libc-test/src/functionalext/supplement/linux/syncfs.c b/libc-test/src/functionalext/supplement/linux/syncfs.c index 9f92349f7..2b67ecff0 100644 --- a/libc-test/src/functionalext/supplement/linux/syncfs.c +++ b/libc-test/src/functionalext/supplement/linux/syncfs.c @@ -30,7 +30,7 @@ void syncfs_0100(void) errno = 0; char path[PATH_MAX] = {0}; 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) { t_error("%s open failed\n", __func__); return; diff --git a/libc-test/src/functionalext/supplement/manual/unistd/isatty.c b/libc-test/src/functionalext/supplement/manual/unistd/isatty.c index bac6d6400..35f9707bb 100755 --- a/libc-test/src/functionalext/supplement/manual/unistd/isatty.c +++ b/libc-test/src/functionalext/supplement/manual/unistd/isatty.c @@ -37,7 +37,7 @@ void isatty_0100() */ 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); EXPECT_EQ("isatty_0200", result, 0); close(fd); diff --git a/libc-test/src/functionalext/supplement/misc/lockf.c b/libc-test/src/functionalext/supplement/misc/lockf.c index c88c1b877..6b41606a0 100644 --- a/libc-test/src/functionalext/supplement/misc/lockf.c +++ b/libc-test/src/functionalext/supplement/misc/lockf.c @@ -27,7 +27,7 @@ const int SIZE = 3; */ 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) { t_error("%s failed: fd = %d\n", __func__, fd); return; @@ -50,7 +50,7 @@ void lockf_0100(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) { t_error("%s failed: fd = %d\n", __func__, fd); return; @@ -73,7 +73,7 @@ void lockf_0200(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) { t_error("%s failed: fd = %d\n", __func__, fd); } @@ -98,7 +98,7 @@ void lockf_0300(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) { t_error("%s failed: fd = %d\n", __func__, fd); } diff --git a/libc-test/src/functionalext/supplement/misc/pty.c b/libc-test/src/functionalext/supplement/misc/pty.c index 83ccf203a..b848c57d6 100644 --- a/libc-test/src/functionalext/supplement/misc/pty.c +++ b/libc-test/src/functionalext/supplement/misc/pty.c @@ -102,27 +102,28 @@ void ptsname_r_0400(void) /** * @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 */ void posix_openpt_0100(void) { int amaster, aslave; - int ret = posix_openpt(O_RDWR | O_CREAT); + int ret = posix_openpt(O_RDWR); EXPECT_NE("posix_openpt_0100", ret, ERREXPECT); - ret = close(ret); + close(ret); } /** * @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 */ void posix_openpt_0200(void) { errno = ENOSPC; - int ret = posix_openpt(O_EXCL | O_CREAT); - EXPECT_EQ("posix_openpt_0200", ret, ERREXPECT); + int ret = posix_openpt(O_RDWR | O_NOCTTY); + EXPECT_NE("posix_openpt_0200", ret, ERREXPECT); + close(ret); } int main(void) diff --git a/libc-test/src/functionalext/supplement/misc/realpath.c b/libc-test/src/functionalext/supplement/misc/realpath.c index 4bda90a97..0192e04df 100644 --- a/libc-test/src/functionalext/supplement/misc/realpath.c +++ b/libc-test/src/functionalext/supplement/misc/realpath.c @@ -37,9 +37,7 @@ void realpath_0100(void) void realpath_0200(void) { char actualPath[4096] = {0}; - char *ret = realpath(NULL, actualPath); - EXPECT_PTREQ("realpath_0200", ret, NULL); - ret = realpath("/system/bin/../mypth", actualPath); + char *ret = realpath("/system/bin/../mypth", actualPath); EXPECT_PTREQ("realpath_0200", ret, NULL); ret = realpath("/system/bin/../etc", NULL); EXPECT_STREQ("realpath_0200", ret, "/system/etc"); diff --git a/libc-test/src/functionalext/supplement/mman/madvise.c b/libc-test/src/functionalext/supplement/mman/madvise.c index 4887e1e14..760d4d2b5 100644 --- a/libc-test/src/functionalext/supplement/mman/madvise.c +++ b/libc-test/src/functionalext/supplement/mman/madvise.c @@ -23,7 +23,7 @@ const char *path = "madvise_function_test.c"; 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) { t_error("open file failed\n"); return -1; diff --git a/libc-test/src/functionalext/supplement/mman/posix_madvise.c b/libc-test/src/functionalext/supplement/mman/posix_madvise.c index 0c1a1fc59..d959a006d 100755 --- a/libc-test/src/functionalext/supplement/mman/posix_madvise.c +++ b/libc-test/src/functionalext/supplement/mman/posix_madvise.c @@ -23,7 +23,7 @@ const char *path = "posix_madvise_function_test.c"; 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) { t_error("open file failed\n"); return -1; diff --git a/libc-test/src/functionalext/supplement/process/fexecve.c b/libc-test/src/functionalext/supplement/process/fexecve.c index a0bbb9b41..1bef120f5 100644 --- a/libc-test/src/functionalext/supplement/process/fexecve.c +++ b/libc-test/src/functionalext/supplement/process/fexecve.c @@ -29,7 +29,7 @@ void fexecve_0100(void) if (fpid == 0) { char *argv[] = {"./fexecverely", NULL}; char *environ[] = {0, NULL}; - int fd = open("fexecverely", O_RDONLY, 0777); + int fd = open("fexecverely", O_RDONLY); int ret = fexecve(fd, argv, environ); EXPECT_NE("fexecve_0100", ret, -1); } diff --git a/libc-test/src/functionalext/supplement/select/poll_sup.c b/libc-test/src/functionalext/supplement/select/poll_sup.c index f50fe61f9..9fb1e67da 100755 --- a/libc-test/src/functionalext/supplement/select/poll_sup.c +++ b/libc-test/src/functionalext/supplement/select/poll_sup.c @@ -35,14 +35,14 @@ void poll_0100(void) struct pollfd fds[2]; 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) { t_error("%s open path1 failed\n", __func__); } write(fd1, str1, strlen(str1) + 1); close(fd1); - int fd2 = open(path2, O_WRONLY | O_CREAT); + int fd2 = open(path2, O_WRONLY | O_CREAT, TEST_MODE); if (fd2 < 0) { t_error("%s open path2 failed\n", __func__); } @@ -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[]) { poll_0100(); poll_0200(); - poll_0300(); return t_status; } \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/stat/chmod.c b/libc-test/src/functionalext/supplement/stat/chmod.c index 0c427d202..811a39680 100644 --- a/libc-test/src/functionalext/supplement/stat/chmod.c +++ b/libc-test/src/functionalext/supplement/stat/chmod.c @@ -25,7 +25,7 @@ void chmod_0100(void) { 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_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); @@ -44,7 +44,7 @@ void chmod_0200(void) { 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); stat("test.txt", &buf); EXPECT_EQ("chmod_0200", result, 0); diff --git a/libc-test/src/functionalext/supplement/stat/fchmod.c b/libc-test/src/functionalext/supplement/stat/fchmod.c index 8a48cca19..478c0195e 100755 --- a/libc-test/src/functionalext/supplement/stat/fchmod.c +++ b/libc-test/src/functionalext/supplement/stat/fchmod.c @@ -28,7 +28,7 @@ void fchmod_0100() { struct stat buf; 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); int result = fchmod(fd, @@ -50,7 +50,7 @@ void fchmod_0200() { struct stat buf; 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); stat(path, &buf); EXPECT_EQ("fchmod_0200", result, 0); diff --git a/libc-test/src/functionalext/supplement/stat/fchmodat.c b/libc-test/src/functionalext/supplement/stat/fchmodat.c index 216aa97ab..99316f3d4 100755 --- a/libc-test/src/functionalext/supplement/stat/fchmodat.c +++ b/libc-test/src/functionalext/supplement/stat/fchmodat.c @@ -33,7 +33,7 @@ void fchmodat_0100(void) struct stat buf; char path[PATH_MAX] = {0}; 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, path, 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) struct stat buf; char path[PATH_MAX] = {0}; 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, path, S_IRWXU | S_IRWXG | S_IRWXO, diff --git a/libc-test/src/functionalext/supplement/stat/fstatat.c b/libc-test/src/functionalext/supplement/stat/fstatat.c index 631a9adb3..6015e6028 100644 --- a/libc-test/src/functionalext/supplement/stat/fstatat.c +++ b/libc-test/src/functionalext/supplement/stat/fstatat.c @@ -33,7 +33,7 @@ void fstatat_0100(void) { const char *ptr = "fstatattest.txt"; 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); lseek(fd, 0, SEEK_SET); int ret = fstatat(AT_FDCWD, ptr, &st, 0); @@ -57,7 +57,7 @@ void fstatat_0200(void) { const char *ptr = "fstatattest.txt"; 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); lseek(fd, 0, SEEK_SET); const char *softptr = "./fstatattest.txt.soft"; @@ -89,7 +89,7 @@ void fstatat_0300(void) FILE_ABSOLUTE_PATH("fstatattest.txt", ptr); 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); lseek(fd, 0, SEEK_SET); int ret = fstatat(0, ptr, &st, 0); @@ -112,7 +112,7 @@ void fstatat_time64_0100(void) { const char *ptr = "fstatat_time64_test.txt"; 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); lseek(fd, 0, SEEK_SET); int ret = __fstatat_time64(AT_FDCWD, ptr, &st, 0); diff --git a/libc-test/src/functionalext/supplement/stat/mknod.c b/libc-test/src/functionalext/supplement/stat/mknod.c index a4895cca3..c11eb1947 100755 --- a/libc-test/src/functionalext/supplement/stat/mknod.c +++ b/libc-test/src/functionalext/supplement/stat/mknod.c @@ -18,8 +18,6 @@ #include "functionalext.h" #include "filepath_util.h" -#define TEST_MODE 0666 - /** * @tc.name : mknod_0100 * @tc.desc : Create file node diff --git a/libc-test/src/functionalext/supplement/stat/utimensat.c b/libc-test/src/functionalext/supplement/stat/utimensat.c index 86274c9b6..582de3996 100644 --- a/libc-test/src/functionalext/supplement/stat/utimensat.c +++ b/libc-test/src/functionalext/supplement/stat/utimensat.c @@ -32,7 +32,7 @@ void utimensat_0100(void) { char path[PATH_MAX] = {0}; 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}}; int result = utimensat(fd, path, times, 0); @@ -82,7 +82,7 @@ void utimensat_time64_0100(void) { char path[PATH_MAX] = {0}; 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}}; int result = __utimensat_time64(fd, path, times, 0); diff --git a/libc-test/src/functionalext/supplement/stdio/dprintf.c b/libc-test/src/functionalext/supplement/stdio/dprintf.c index 2283f5d1f..adcfb7746 100644 --- a/libc-test/src/functionalext/supplement/stdio/dprintf.c +++ b/libc-test/src/functionalext/supplement/stdio/dprintf.c @@ -51,7 +51,7 @@ void dprintf_0200(void) void dprintf_0300(void) { 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); int result = dprintf(fd, "This is a test!"); @@ -72,7 +72,7 @@ void dprintf_0300(void) void dprintf_0400(void) { 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); int result = dprintf(fd, "This is a test!"); diff --git a/libc-test/src/functionalext/supplement/stdio/fgetws.c b/libc-test/src/functionalext/supplement/stdio/fgetws.c index 55c43d3c6..a539aeb0f 100644 --- a/libc-test/src/functionalext/supplement/stdio/fgetws.c +++ b/libc-test/src/functionalext/supplement/stdio/fgetws.c @@ -57,7 +57,7 @@ void fgetws_0200() FILE *fptr = fopen(ptr, "w+"); EXPECT_PTRNE("fgetws_0100", fptr, NULL); - fwrite(line, sizeof(char), 100, fptr); + fwrite(line, sizeof(line) / sizeof(wchar_t), sizeof(*line), fptr); fflush(fptr); wchar_t *ch = fgetws(wrstring, EINVAL, fptr); diff --git a/libc-test/src/functionalext/supplement/stdio/getchar.c b/libc-test/src/functionalext/supplement/stdio/getchar.c index fcc63d7ab..1fcc07e38 100644 --- a/libc-test/src/functionalext/supplement/stdio/getchar.c +++ b/libc-test/src/functionalext/supplement/stdio/getchar.c @@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt"; void getchar_0100(void) { char str[] = "t"; - int fd = open(path, O_RDWR | O_CREAT); + int fd = open(path, O_RDWR | O_CREAT, TEST_MODE); if (fd < 0) { t_error("%s open failed\n", __func__); } diff --git a/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c b/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c index 5dd513228..d54d58cb4 100644 --- a/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c +++ b/libc-test/src/functionalext/supplement/stdio/getchar_unlocked.c @@ -27,7 +27,7 @@ const char *path = "/data/readtest.txt"; void getchar_unlocked_0100(void) { char str[] = "r"; - int fd = open(path, O_RDWR | O_CREAT); + int fd = open(path, O_RDWR | O_CREAT, TEST_MODE); if (fd < 0) { t_error("%s open failed\n", __func__); } diff --git a/libc-test/src/functionalext/supplement/stdio/rename.c b/libc-test/src/functionalext/supplement/stdio/rename.c index e11ed0376..488ed20dd 100644 --- a/libc-test/src/functionalext/supplement/stdio/rename.c +++ b/libc-test/src/functionalext/supplement/stdio/rename.c @@ -25,7 +25,7 @@ void rename_0100(void) { const char *oldname = "oldfile.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); close(fd); @@ -61,7 +61,7 @@ void rename_0300(void) { const char *oldname = "oldfile.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); char str_old[] = "old"; @@ -69,7 +69,7 @@ void rename_0300(void) EXPECT_TRUE("rename_0300", ret_old > 0); 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); char str_new[] = "new"; diff --git a/libc-test/src/functionalext/supplement/stdio/vdprintf.c b/libc-test/src/functionalext/supplement/stdio/vdprintf.c index 11f58bcd1..37d659b30 100644 --- a/libc-test/src/functionalext/supplement/stdio/vdprintf.c +++ b/libc-test/src/functionalext/supplement/stdio/vdprintf.c @@ -37,7 +37,7 @@ void vdprintf_0100(void) { char *value = "asdf"; 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) { t_error("%s open failed", __func__); return; diff --git a/libc-test/src/functionalext/supplement/unistd/dup3.c b/libc-test/src/functionalext/supplement/unistd/dup3.c index 8c5cba2f5..f2c4f2b04 100644 --- a/libc-test/src/functionalext/supplement/unistd/dup3.c +++ b/libc-test/src/functionalext/supplement/unistd/dup3.c @@ -25,7 +25,7 @@ const int FAILED = -1; */ 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); int ret = dup3(fd, fileno(stderr), O_CLOEXEC); EXPECT_EQ("dup3_0100", ret, fileno(stderr)); @@ -53,7 +53,7 @@ void dup3_0200(void) void dup3_0300(void) { 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); int ret = dup3(fd, newfd, O_CLOEXEC); EXPECT_EQ("dup3_0300", ret, FAILED); diff --git a/libc-test/src/functionalext/supplement/unistd/faccessat.c b/libc-test/src/functionalext/supplement/unistd/faccessat.c index df3753998..6cb1fb981 100644 --- a/libc-test/src/functionalext/supplement/unistd/faccessat.c +++ b/libc-test/src/functionalext/supplement/unistd/faccessat.c @@ -32,7 +32,7 @@ void faccessat_0100(void) { char ptr[PATH_MAX] = {0}; 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); int isExist = faccessat(fd, ptr, F_OK, 0); EXPECT_EQ("faccessat_0100", isExist, SUCCESS); @@ -119,7 +119,7 @@ void faccessat_0600(void) { char ptr[PATH_MAX] = {0}; 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); int isExecute = faccessat(fd, ptr, X_OK, 0); EXPECT_EQ("faccessat_0600", isExecute, FAILED); @@ -153,7 +153,7 @@ void faccessat_0800(void) { char ptr[PATH_MAX] = {0}; 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); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); EXPECT_EQ("faccessat_0800", isExecute, FAILED); @@ -207,7 +207,7 @@ void faccessat_1100(void) { char ptr[PATH_MAX] = {0}; 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); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); EXPECT_EQ("faccessat_1100", isExecute, FAILED); diff --git a/libc-test/src/functionalext/supplement/unistd/fchown.c b/libc-test/src/functionalext/supplement/unistd/fchown.c index ef21ecf46..6f2c9fa9e 100644 --- a/libc-test/src/functionalext/supplement/unistd/fchown.c +++ b/libc-test/src/functionalext/supplement/unistd/fchown.c @@ -33,7 +33,7 @@ const int COUNT_NEFATIVE = -1; */ 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); struct stat buff; EXPECT_EQ("fchown_0100", result, COUNT_ZERO); @@ -50,7 +50,7 @@ void fchown_0100() */ 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); struct stat buff; EXPECT_EQ("fchown_0200", result, COUNT_ZERO); @@ -67,7 +67,7 @@ void fchown_0200() */ 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); struct stat buff; EXPECT_EQ("fchown_0300", result, COUNT_ZERO); @@ -84,7 +84,7 @@ void fchown_0300() */ 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); int result = fchown(fd, 0, 0); EXPECT_EQ("fchown_0400", result, COUNT_NEFATIVE); @@ -98,7 +98,7 @@ void fchown_0400() */ 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); EXPECT_EQ("fchown_0500", result, COUNT_NEFATIVE); close(fd); diff --git a/libc-test/src/functionalext/supplement/unistd/fchownat.c b/libc-test/src/functionalext/supplement/unistd/fchownat.c index e20599c14..293388ebc 100644 --- a/libc-test/src/functionalext/supplement/unistd/fchownat.c +++ b/libc-test/src/functionalext/supplement/unistd/fchownat.c @@ -28,7 +28,7 @@ void fchownat_0100(void) { char ptr[PATH_MAX] = {0}; 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); int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); EXPECT_EQ("fchownat_0100", ret, 0); @@ -50,7 +50,7 @@ void fchownat_0200(void) { char ptr[PATH_MAX] = {0}; 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); int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); EXPECT_EQ("fchownat_0200", ret, 0); diff --git a/libc-test/src/functionalext/supplement/unistd/fdatasync.c b/libc-test/src/functionalext/supplement/unistd/fdatasync.c index 02b4cef2f..d2670fe74 100755 --- a/libc-test/src/functionalext/supplement/unistd/fdatasync.c +++ b/libc-test/src/functionalext/supplement/unistd/fdatasync.c @@ -30,7 +30,7 @@ void fdatasync_0100() { char str[] = "hello"; 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); write(fd, str, sizeof(str)); @@ -54,7 +54,7 @@ void fdatasync_0200() { char str[] = "hello\n"; 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); close(fd); diff --git a/libc-test/src/functionalext/supplement/unistd/fsync.c b/libc-test/src/functionalext/supplement/unistd/fsync.c index b1709e666..dc51f813c 100644 --- a/libc-test/src/functionalext/supplement/unistd/fsync.c +++ b/libc-test/src/functionalext/supplement/unistd/fsync.c @@ -26,7 +26,7 @@ const char *path = "/data/test.txt"; */ 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); int result = fsync(fd); diff --git a/libc-test/src/functionalext/supplement/unistd/lseek.c b/libc-test/src/functionalext/supplement/unistd/lseek.c index a6539d53f..eb1d77cfc 100644 --- a/libc-test/src/functionalext/supplement/unistd/lseek.c +++ b/libc-test/src/functionalext/supplement/unistd/lseek.c @@ -36,7 +36,7 @@ void lseek64_0100(void) { off64_t DataArry[TEST_BUFFER_SIZE] = {1, 2, 4, 8}; 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) { t_error("open file failed\n"); return; @@ -63,7 +63,7 @@ void lseek64_0100(void) void lseek_0100(void) { 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); int retwrite = write(fd, wrstring, sizeof(wrstring)); off_t data = lseek(fd, 0L, SEEK_SET); @@ -80,7 +80,7 @@ void lseek_0100(void) void lseek_0200(void) { 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); int retwrite = write(fd, wrstring, sizeof(wrstring)); off_t data = lseek(fd, 8L, SEEK_SET); @@ -97,7 +97,7 @@ void lseek_0200(void) void lseek_0300(void) { 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); int retwrite = write(fd, wrstring, sizeof(wrstring)); off_t data = lseek(fd, 10L, SEEK_SET); @@ -115,7 +115,7 @@ void lseek_0300(void) void lseek_0400(void) { 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); int retwrite = write(fd, str, sizeof(str)); off_t data = lseek(fd, -1L, SEEK_END); @@ -132,7 +132,7 @@ void lseek_0400(void) void lseek_0500(void) { 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); int retwrite = write(fd, str, sizeof(str)); off_t data = lseek(fd, -10L, SEEK_SET); @@ -149,7 +149,7 @@ void lseek_0500(void) void lseek_0600(void) { 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); int retwrite = write(fd, str, sizeof(str)); off_t data = lseek(fd, 10L, SEEK_END); diff --git a/libc-test/src/functionalext/supplement/unistd/preadv.c b/libc-test/src/functionalext/supplement/unistd/preadv.c index 358370156..a65392633 100755 --- a/libc-test/src/functionalext/supplement/unistd/preadv.c +++ b/libc-test/src/functionalext/supplement/unistd/preadv.c @@ -40,7 +40,7 @@ void preadv_0100(void) iov[1].iov_base = buf2; 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) { EXPECT_NE("preadv_0100", fd, ERREXPECT); return; diff --git a/libc-test/src/functionalext/supplement/unistd/pwrite.c b/libc-test/src/functionalext/supplement/unistd/pwrite.c index 133381d3f..76c53ff41 100755 --- a/libc-test/src/functionalext/supplement/unistd/pwrite.c +++ b/libc-test/src/functionalext/supplement/unistd/pwrite.c @@ -19,7 +19,6 @@ #include "functionalext.h" #define TEST_BUFFER_SIZE 64 -#define TEST_MODE 0777 void rm_file(const char *name) { diff --git a/libc-test/src/functionalext/supplement/unistd/pwritev.c b/libc-test/src/functionalext/supplement/unistd/pwritev.c index 353129af0..9c22b3fb3 100755 --- a/libc-test/src/functionalext/supplement/unistd/pwritev.c +++ b/libc-test/src/functionalext/supplement/unistd/pwritev.c @@ -34,7 +34,7 @@ void pwritev_0100(void) iov[1].iov_base = buf2; 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 ret = pwritev(fd, iov, count, 0); EXPECT_NE("pwritev_0100", ret, EOF); @@ -63,7 +63,7 @@ void pwritev_0200(void) iov[1].iov_base = buf2; 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) { EXPECT_NE("pwritev_0200", fd, ERREXPECT); return; diff --git a/libc-test/src/functionalext/supplement/unistd/read.c b/libc-test/src/functionalext/supplement/unistd/read.c index f98d5f152..86fd76fb3 100644 --- a/libc-test/src/functionalext/supplement/unistd/read.c +++ b/libc-test/src/functionalext/supplement/unistd/read.c @@ -27,7 +27,7 @@ void read_0100(void) { char str[] = "this is a readtest\n"; 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); int retwrite = write(fd, str, sizeof(str)); EXPECT_EQ("read_0100", retwrite, SIZE); diff --git a/libc-test/src/functionalext/supplement/unistd/readlinkat.c b/libc-test/src/functionalext/supplement/unistd/readlinkat.c index 803e7b90e..da2f9c0b7 100644 --- a/libc-test/src/functionalext/supplement/unistd/readlinkat.c +++ b/libc-test/src/functionalext/supplement/unistd/readlinkat.c @@ -27,7 +27,7 @@ const char *linkfilename = "./linkfile.txt"; 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) { return -1; } diff --git a/libc-test/src/functionalext/supplement/unistd/readv.c b/libc-test/src/functionalext/supplement/unistd/readv.c index d2ae41689..984c6c2cb 100644 --- a/libc-test/src/functionalext/supplement/unistd/readv.c +++ b/libc-test/src/functionalext/supplement/unistd/readv.c @@ -30,7 +30,7 @@ void readv_0100(void) { char path[PATH_MAX] = {0}; 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 buf2[] = "world"; diff --git a/libc-test/src/functionalext/supplement/unistd/ttyname_r.c b/libc-test/src/functionalext/supplement/unistd/ttyname_r.c index 37166798c..fd3e2e154 100644 --- a/libc-test/src/functionalext/supplement/unistd/ttyname_r.c +++ b/libc-test/src/functionalext/supplement/unistd/ttyname_r.c @@ -28,7 +28,7 @@ */ 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]; int want = 25; int result = ttyname_r(fd, buf, sizeof(buf)); diff --git a/libc-test/src/functionalext/supplement/unistd/unlink.c b/libc-test/src/functionalext/supplement/unistd/unlink.c index 2149e6022..096421fe2 100644 --- a/libc-test/src/functionalext/supplement/unistd/unlink.c +++ b/libc-test/src/functionalext/supplement/unistd/unlink.c @@ -28,7 +28,7 @@ void unlink_0100(void) { char path[PATH_MAX] = {0}; 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; if (fd == error_code) { t_error("%s unlink create file error", __func__); diff --git a/libc-test/src/functionalext/time/strptime_ext.c b/libc-test/src/functionalext/time/strptime_ext.c index fee783e04..89fc39a28 100644 --- a/libc-test/src/functionalext/time/strptime_ext.c +++ b/libc-test/src/functionalext/time/strptime_ext.c @@ -189,7 +189,7 @@ void strptime_0700(void) strptime(buffer, "%s", &tmTime); second = mktime(&tmTime); char buffResult[gBufferSize]; - int cnt = sprintf(buffResult, "%ld", second); + int cnt = sprintf(buffResult, "%lld", second); EXPECT_TRUE("strptime_0700", cnt > 0); EXPECT_STREQ("strptime_0700", buffer, buffResult); } diff --git a/libc-test/src/functionalext/trace/trace_marker.c b/libc-test/src/functionalext/trace/trace_marker.c index 9336c78bd..b6fe7153c 100644 --- a/libc-test/src/functionalext/trace/trace_marker.c +++ b/libc-test/src/functionalext/trace/trace_marker.c @@ -74,7 +74,7 @@ static void dump_trace(int trace_fd) char buffer[READ_BUFFER_SIZE]; int nwrite; 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) { return; } diff --git a/libc-test/test_template.gni b/libc-test/test_template.gni index 18b8c1aac..863f80f1b 100644 --- a/libc-test/test_template.gni +++ b/libc-test/test_template.gni @@ -146,7 +146,7 @@ template("test_unittest") { if (!defined(defines)) { defines = [] } - defines += [ "MUSL_FORTIFY_SOURCE=2" ] + defines += [ "_FORTIFY_SOURCE=2" ] } if (target_dir == "functionalext/ldso_randomization") { diff --git a/libc.map.txt b/libc.map.txt index 99876ff63..f483566a8 100644 --- a/libc.map.txt +++ b/libc.map.txt @@ -140,7 +140,7 @@ __lutimes_time64; __lxstat; __lxstat64; - __memchr_diagnose; + __memchr_chk; __memcpy_chk; # __memmove_aarch64; __memmove_chk; @@ -156,14 +156,14 @@ __newlocale; __nl_langinfo; __nl_langinfo_l; - __open_diagnose; - __open64_diagnose; - __openat_diagnose; - __openat64_diagnose; + __open_chk; + __open64_chk; + __openat_chk; + __openat64_chk; # __optpos; __optreset; __overflow; - __poll_diagnose; + __poll_chk; __posix_getopt; __ppoll_chk; __ppoll_time64; @@ -184,8 +184,8 @@ __readlink_chk; __readlinkat_chk; # __reboot; - __recv_diagnose; - __recvfrom_diagnose; + __recv_chk; + __recvfrom_chk; __recvmmsg_time64; # __res_state; __sched_cpualloc; @@ -194,8 +194,8 @@ __select_time64; __sem_timedwait_time64; __semtimedop_time64; - __send_diagnose; - __sendto_diagnose; + __send_chk; + __sendto_chk; __setitimer_time64; __setjmp; __settimeofday_time64; @@ -215,17 +215,17 @@ __stpncpy_chk; __strcasecmp_l; __strcat_chk; - __strchr_diagnose; + __strchr_chk; __strcoll_l; __strcpy_chk; __strerror_l; - __strlcat_diagnose; - __strlcpy_diagnose; + __strlcat_chk; + __strlcpy_chk; __strlen_chk; __strncasecmp_l; __strncat_chk; __strncpy_chk; - __strrchr_diagnose; + __strrchr_chk; __strtod_l; __strtof_l; __strtoimax_internal; @@ -254,7 +254,7 @@ __towupper_l; __tzname; __uflow; - __umask_diagnose; + __umask_chk; __uselocale; __utime64; __utimensat_time64; diff --git a/ndk_musl_include/fcntl.h b/ndk_musl_include/fcntl.h index b664cdc44..98c165f1c 100644 --- a/ndk_musl_include/fcntl.h +++ b/ndk_musl_include/fcntl.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include struct flock { short l_type; diff --git a/ndk_musl_include/fortify/fcntl.h b/ndk_musl_include/fortify/fcntl.h new file mode 100644 index 000000000..af46bd13f --- /dev/null +++ b/ndk_musl_include/fortify/fcntl.h @@ -0,0 +1,129 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/fortify/fortify.h b/ndk_musl_include/fortify/fortify.h new file mode 100644 index 000000000..961a163b9 --- /dev/null +++ b/ndk_musl_include/fortify/fortify.h @@ -0,0 +1,137 @@ +/* + * 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 diff --git a/ndk_musl_include/fortify/poll.h b/ndk_musl_include/fortify/poll.h new file mode 100644 index 000000000..69497835d --- /dev/null +++ b/ndk_musl_include/fortify/poll.h @@ -0,0 +1,72 @@ +/* + * 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 " +#endif + +#include +#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 diff --git a/ndk_musl_include/fortify/socket.h b/ndk_musl_include/fortify/socket.h new file mode 100644 index 000000000..f23dbef07 --- /dev/null +++ b/ndk_musl_include/fortify/socket.h @@ -0,0 +1,104 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/fortify/stat.h b/ndk_musl_include/fortify/stat.h new file mode 100644 index 000000000..bdaee62b9 --- /dev/null +++ b/ndk_musl_include/fortify/stat.h @@ -0,0 +1,47 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/fortify/stdio.h b/ndk_musl_include/fortify/stdio.h new file mode 100644 index 000000000..1e7de8563 --- /dev/null +++ b/ndk_musl_include/fortify/stdio.h @@ -0,0 +1,136 @@ +/* + * 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 " +#endif + +#include +#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 diff --git a/ndk_musl_include/fortify/stdlib.h b/ndk_musl_include/fortify/stdlib.h new file mode 100644 index 000000000..a0d3b4670 --- /dev/null +++ b/ndk_musl_include/fortify/stdlib.h @@ -0,0 +1,34 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/fortify/string.h b/ndk_musl_include/fortify/string.h new file mode 100644 index 000000000..00846b8ec --- /dev/null +++ b/ndk_musl_include/fortify/string.h @@ -0,0 +1,246 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/fortify/unistd.h b/ndk_musl_include/fortify/unistd.h new file mode 100644 index 000000000..39d0a5b87 --- /dev/null +++ b/ndk_musl_include/fortify/unistd.h @@ -0,0 +1,171 @@ +/* + * 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 " +#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 diff --git a/ndk_musl_include/poll.h b/ndk_musl_include/poll.h index 472e4b847..b7df3dba8 100644 --- a/ndk_musl_include/poll.h +++ b/ndk_musl_include/poll.h @@ -50,6 +50,8 @@ __REDIR(ppoll, __ppoll_time64); #endif #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/stdio.h b/ndk_musl_include/stdio.h index 286aaac02..f27fddf6a 100644 --- a/ndk_musl_include/stdio.h +++ b/ndk_musl_include/stdio.h @@ -212,6 +212,8 @@ typedef struct _IO_cookie_io_functions_t { #define off64_t off_t #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/stdlib.h b/ndk_musl_include/stdlib.h index 1485c5d25..f0087d560 100644 --- a/ndk_musl_include/stdlib.h +++ b/ndk_musl_include/stdlib.h @@ -161,6 +161,8 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale #endif #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/string.h b/ndk_musl_include/string.h index 02d983ef8..d5674407d 100644 --- a/ndk_musl_include/string.h +++ b/ndk_musl_include/string.h @@ -96,6 +96,8 @@ char *basename(); #endif #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/sys/socket.h b/ndk_musl_include/sys/socket.h index fca119414..a49ff7685 100644 --- a/ndk_musl_include/sys/socket.h +++ b/ndk_musl_include/sys/socket.h @@ -411,6 +411,8 @@ __REDIR(recvmmsg, __recvmmsg_time64); #endif #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/sys/stat.h b/ndk_musl_include/sys/stat.h index 25c8b2212..3c8147403 100644 --- a/ndk_musl_include/sys/stat.h +++ b/ndk_musl_include/sys/stat.h @@ -118,6 +118,8 @@ __REDIR(futimens, __futimens_time64); __REDIR(utimensat, __utimensat_time64); #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_musl_include/unistd.h b/ndk_musl_include/unistd.h index fc1794db4..088f1c900 100644 --- a/ndk_musl_include/unistd.h +++ b/ndk_musl_include/unistd.h @@ -462,6 +462,8 @@ pid_t gettid(void); #endif #endif +#include + #ifdef __cplusplus } #endif diff --git a/ndk_script/adapter/libc.ndk.json b/ndk_script/adapter/libc.ndk.json index 5fa6bc830..f2d12fd6a 100644 --- a/ndk_script/adapter/libc.ndk.json +++ b/ndk_script/adapter/libc.ndk.json @@ -1516,5 +1516,47 @@ { "name": "pthread_rwlock_timedwrlock_monotonic_np" }, { "name": "set_application_target_sdk_version" }, { "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"} ] diff --git a/porting/linux/user/include/fortify/fcntl.h b/porting/linux/user/include/fortify/fcntl.h index be44fbd26..af46bd13f 100644 --- a/porting/linux/user/include/fortify/fcntl.h +++ b/porting/linux/user/include/fortify/fcntl.h @@ -23,11 +23,11 @@ extern "C" { #endif -int __open_diagnose(const char*, int); -int __openat_diagnose(int, const char*, int); +int __open_chk(const char*, int); +int __openat_chk(int, const char*, int); #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -int __open64_diagnose(const char*, int); -int __openat64_diagnose(int, const char*, int); +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. @@ -46,7 +46,7 @@ __DIAGNOSE_OVERLOAD __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open' " OPEN_TOO_FEW_ARGS_ERROR) { #ifdef __FORTIFY_RUNTIME - return __open_diagnose(path, flags); + return __open_chk(path, flags); #else return __open_real(path, flags); #endif @@ -66,7 +66,7 @@ __DIAGNOSE_OVERLOAD __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat' " OPEN_TOO_FEW_ARGS_ERROR) { #ifdef __FORTIFY_RUNTIME - return __openat_diagnose(dirfd, path, flags); + return __openat_chk(dirfd, path, flags); #else return __openat_real(dirfd, path, flags); #endif @@ -87,7 +87,7 @@ __DIAGNOSE_OVERLOAD __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'open64' " OPEN_TOO_FEW_ARGS_ERROR) { #ifdef __FORTIFY_RUNTIME - return __open64_diagnose(path, flags); + return __open64_chk(path, flags); #else return __open64_real(path, flags); #endif @@ -107,7 +107,7 @@ __DIAGNOSE_OVERLOAD __DIAGNOSE_ERROR_IF(__DIAGNOSE_OPEN_MODES_USEFUL(flags), "'openat64' " OPEN_TOO_FEW_ARGS_ERROR) { #ifdef __FORTIFY_RUNTIME - return __openat64_diagnose(dirfd, path, flags); + return __openat64_chk(dirfd, path, flags); #else return __openat64_real(dirfd, path, flags); #endif diff --git a/porting/linux/user/include/fortify/fortify.h b/porting/linux/user/include/fortify/fortify.h index 33010f5ac..961a163b9 100644 --- a/porting/linux/user/include/fortify/fortify.h +++ b/porting/linux/user/include/fortify/fortify.h @@ -20,13 +20,13 @@ extern "C" { #endif -#if (MUSL_FORTIFY_SOURCE == 1) || (MUSL_FORTIFY_SOURCE == 2) +#if (_FORTIFY_SOURCE == 1) || (_FORTIFY_SOURCE == 2) #ifndef __FORTIFY_COMPILATION #define __FORTIFY_COMPILATION #endif #endif -#if (MUSL_FORTIFY_SOURCE == 2) +#if (_FORTIFY_SOURCE == 2) #ifndef __FORTIFY_RUNTIME #define __FORTIFY_RUNTIME #endif diff --git a/porting/linux/user/include/fortify/poll.h b/porting/linux/user/include/fortify/poll.h index 4e7d622ec..69497835d 100644 --- a/porting/linux/user/include/fortify/poll.h +++ b/porting/linux/user/include/fortify/poll.h @@ -24,7 +24,7 @@ extern "C" { #endif -int __poll_diagnose(struct pollfd*, nfds_t, int, size_t); +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 @@ -40,7 +40,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(fds), sizeof(*fds) size_t bos_fds = __DIAGNOSE_BOS(fds); 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 return __DIAGNOSE_CALL_BYPASSING_FORTIFY(poll)(fds, fd_amount, timeout); diff --git a/porting/linux/user/include/fortify/socket.h b/porting/linux/user/include/fortify/socket.h index 5d5d99da4..f23dbef07 100644 --- a/porting/linux/user/include/fortify/socket.h +++ b/porting/linux/user/include/fortify/socket.h @@ -23,12 +23,12 @@ extern "C" { #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); -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*); -ssize_t __send_diagnose(int, const void*, size_t, size_t, int); -ssize_t __recv_diagnose(int, void*, size_t, size_t, int); +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 @@ -43,7 +43,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), size_t bos = __DIAGNOSE_BOS0(buf); 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 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), size_t bos = __DIAGNOSE_BOS0(buf); 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 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), size_t bos = __DIAGNOSE_BOS0(buf); if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { - return __recv_diagnose(socket, buf, len, bos, flags); + return __recv_chk(socket, buf, len, bos, flags); } #endif return __DIAGNOSE_CALL_BYPASSING_FORTIFY(recv)(socket, buf, len, flags); @@ -92,7 +92,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), len), size_t bos = __DIAGNOSE_BOS0(buf); if (!__DIAGNOSE_BOS_TRIVIALLY_GE(bos, len)) { - return __send_diagnose(socket, buf, len, bos, flags); + return __send_chk(socket, buf, len, bos, flags); } #endif return __DIAGNOSE_CALL_BYPASSING_FORTIFY(send)(socket, buf, len, flags); diff --git a/porting/linux/user/include/fortify/stat.h b/porting/linux/user/include/fortify/stat.h index ac45d21a6..bdaee62b9 100644 --- a/porting/linux/user/include/fortify/stat.h +++ b/porting/linux/user/include/fortify/stat.h @@ -23,7 +23,7 @@ extern "C" { #endif -mode_t __umask_diagnose(mode_t); +mode_t __umask_chk(mode_t); mode_t __umask_real(mode_t mode) __DIAGNOSE_RENAME(umask); #ifdef __FORTIFY_COMPILATION @@ -35,7 +35,7 @@ __DIAGNOSE_ENABLE_IF(1, "") __DIAGNOSE_ERROR_IF(mode & ~0777, "'umask' was called in invalid mode") { #ifdef __FORTIFY_RUNTIME - return __umask_diagnose(mode); + return __umask_chk(mode); #else return __umask_real(mode); #endif diff --git a/porting/linux/user/include/fortify/string.h b/porting/linux/user/include/fortify/string.h index 87cb3ba80..00846b8ec 100644 --- a/porting/linux/user/include/fortify/string.h +++ b/porting/linux/user/include/fortify/string.h @@ -23,12 +23,12 @@ extern "C" { #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); -size_t __strlcpy_diagnose(char*, const char*, size_t, size_t); -size_t __strlcat_diagnose(char*, const char*, size_t, size_t); -char *__strchr_diagnose(const char* p, int ch, size_t s_len); -char *__strrchr_diagnose(const char *p, int ch, size_t s_len); +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 @@ -143,7 +143,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size), "'strlcpy' called with size bigger than buffer") { #ifdef __FORTIFY_RUNTIME - return __strlcpy_diagnose(dest, src, size, __DIAGNOSE_BOS(dest)); + return __strlcpy_chk(dest, src, size, __DIAGNOSE_BOS(dest)); #else return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcpy)(dest, src, size); #endif @@ -156,7 +156,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(dest), size), "'strlcat' called with size bigger than buffer") { #ifdef __FORTIFY_RUNTIME - return __strlcat_diagnose(dest, src, size, __DIAGNOSE_BOS(dest)); + return __strlcat_chk(dest, src, size, __DIAGNOSE_BOS(dest)); #else return __DIAGNOSE_CALL_BYPASSING_FORTIFY(strlcat)(dest, src, size); #endif @@ -184,7 +184,7 @@ __DIAGNOSE_OVERLOAD if (__DIAGNOSE_BOS_TRIVIALLY_GE(bos, 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 @@ -211,7 +211,7 @@ __DIAGNOSE_OVERLOAD size_t bos = __DIAGNOSE_BOS(s); if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) { - return __strchr_diagnose(s, c, bos); + return __strchr_chk(s, c, bos); } #endif return __builtin_strchr(s, c); @@ -225,7 +225,7 @@ __DIAGNOSE_OVERLOAD size_t bos = __DIAGNOSE_BOS(s); if (bos != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE) { - return __strrchr_diagnose(s, c, bos); + return __strrchr_chk(s, c, bos); } #endif return __builtin_strrchr(s, c); diff --git a/porting/linux/user/src/fortify/fortify.c b/porting/linux/user/src/fortify/fortify.c index 28292f7b1..d30c6c8aa 100644 --- a/porting/linux/user/src/fortify/fortify.c +++ b/porting/linux/user/src/fortify/fortify.c @@ -57,7 +57,7 @@ static inline bool __needs_mode(int flags) 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)) { __fortify_error("open: " OPEN_TOO_FEW_ARGS_ERROR); @@ -65,7 +65,7 @@ int __open_diagnose(const char* pathname, int flags) 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)) { __fortify_error("openat: " OPEN_TOO_FEW_ARGS_ERROR); @@ -74,7 +74,7 @@ int __openat_diagnose(int fd, const char* pathname, int flags) } #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)) { __fortify_error("open64: " OPEN_TOO_FEW_ARGS_ERROR); @@ -82,7 +82,7 @@ int __open64_diagnose(const char* pathname, int flags) 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)) { __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 } } -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); 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, } } -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) { __diagnose_buffer_access("recvfrom", "write into", len, buf_size); 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) { __diagnose_buffer_access("sendto", "read from", len, buflen); 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); 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); 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)) { __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) 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); void* const_cast_s = s; @@ -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) { __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); } @@ -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) -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) { __diagnose_buffer_access("strlcpy", "write into", supplied_size, dst_len_from_compiler); 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) { __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, } #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) { __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) 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) { __fortify_error("strrchr: avoid read exceed end of buffer\n"); -- Gitee