From dafef34674e5adecd5f54f18ff8542f996d6eadf Mon Sep 17 00:00:00 2001 From: ganlan Date: Tue, 30 Aug 2022 03:52:48 +0800 Subject: [PATCH] update test script and rename fortity macro Signed-off-by: ganlan --- libc-test/src/functionalext/fortify/string.c | 12 ++++++----- libc-test/src/functionalext/fortify/unistd.c | 1 + libc-test/test_template.gni | 5 ++++- porting/linux/user/include/fortify/fortify.h | 22 ++++++++++---------- porting/linux/user/include/fortify/stdlib.h | 2 +- porting/linux/user/include/fortify/unistd.h | 6 +++--- porting/linux/user/src/fortify/fortify.c | 1 + scripts/runtest.sh | 2 ++ scripts/runtest_Windows.bat | 6 +++--- 9 files changed, 33 insertions(+), 24 deletions(-) diff --git a/libc-test/src/functionalext/fortify/string.c b/libc-test/src/functionalext/fortify/string.c index b6b55c25..b9b5786c 100644 --- a/libc-test/src/functionalext/fortify/string.c +++ b/libc-test/src/functionalext/fortify/string.c @@ -12,13 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include +#include #include #include #include #include #include "fortify_test.h" -#include "test.h" +#include "test.h" #define SIZE_1 1 #define SIZE_5 5 @@ -556,7 +558,7 @@ static void test_strlcpy_0020() }; sigaction(SIGABRT, &sigabrt, NULL); - + char src[SIZE_15]; char dst[SIZE_10]; strcpy(src, STRLEN_14); @@ -781,7 +783,7 @@ static void test_memcpy_0020() }; sigaction(SIGABRT, &sigabrt, NULL); - + int status; char dst[SIZE_10]; int pid = fork(); @@ -827,7 +829,7 @@ static void test_memset_0020() .sa_handler = SignalHandler, }; sigaction(SIGABRT, &sigabrt, NULL); - + char buf[SIZE_10]; size_t n = atoi(EQ_11); int status; @@ -856,7 +858,7 @@ static void test_strlen_0010() .sa_handler = SignalHandler, }; sigaction(SIGABRT, &sigabrt, NULL); - + char buf[SIZE_10]; memcpy(buf, STRLEN_10, sizeof(buf)); int status; diff --git a/libc-test/src/functionalext/fortify/unistd.c b/libc-test/src/functionalext/fortify/unistd.c index a925359a..8476a341 100644 --- a/libc-test/src/functionalext/fortify/unistd.c +++ b/libc-test/src/functionalext/fortify/unistd.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include diff --git a/libc-test/test_template.gni b/libc-test/test_template.gni index e61b53cc..e1320d44 100644 --- a/libc-test/test_template.gni +++ b/libc-test/test_template.gni @@ -125,7 +125,10 @@ template("test_unittest") { } if (target_dir == "functionalext/fortify") { - defines = [ "MUSL_FORTIFY_SOURCE=2" ] + if (!defined(defines)) { + defines = [] + } + defines += [ "MUSL_FORTIFY_SOURCE=2" ] } if (target_dir == "functionalext/ldso_randomization") { diff --git a/porting/linux/user/include/fortify/fortify.h b/porting/linux/user/include/fortify/fortify.h index ff385223..a3cc002a 100644 --- a/porting/linux/user/include/fortify/fortify.h +++ b/porting/linux/user/include/fortify/fortify.h @@ -39,22 +39,22 @@ extern "C" { #endif #if defined(__LP64__) -#ifndef LONG_MAX -#define LONG_MAX 0x7fffffffffffffffL +#ifndef FORTIFY_LONG_MAX +#define FORTIFY_LONG_MAX 0x7fffffffffffffffL #endif -#ifndef SSIZE_MAX -#define SSIZE_MAX LONG_MAX +#ifndef FORTIFY_SSIZE_MAX +#define FORTIFY_SSIZE_MAX FORTIFY_LONG_MAX #endif #else -#ifndef LONG_MAX -#define LONG_MAX 0x7fffffffL +#ifndef FORTIFY_LONG_MAX +#define FORTIFY_LONG_MAX 0x7fffffffL #endif -#ifndef SSIZE_MAX -#define SSIZE_MAX LONG_MAX +#ifndef FORTIFY_SSIZE_MAX +#define FORTIFY_SSIZE_MAX FORTIFY_LONG_MAX #endif #endif -#ifndef PATH_MAX -#define PATH_MAX 4096 +#ifndef FORTIFY_PATH_MAX +#define FORTIFY_PATH_MAX 4096 #endif #define __DIAGNOSE_ALWAYS_INLINE __attribute__((__always_inline__)) @@ -122,7 +122,7 @@ extern "C" { #define CALLED_WITH_STRING_BIGGER_BUFFER "called with string bigger than buffer" #define FD_COUNT_LARGE_GIVEN_BUFFER "fd_count is larger than the given buffer" #define CALLED_WITH_SIZE_BIGGER_BUFFER "called with size bigger than buffer" -#define OUTPUT_PARAMETER_BYTES "output parameter must be NULL or a pointer to a buffer with >= PATH_MAX bytes" +#define OUTPUT_PARAMETER_BYTES "output parameter must be NULL or a pointer to a buffer with >= FORTIFY_PATH_MAX bytes" #define SIZE_LARGER_THEN_DESTINATION_BUFFER "size is larger than the destination buffer" void __fortify_error(const char* info, ...); diff --git a/porting/linux/user/include/fortify/stdlib.h b/porting/linux/user/include/fortify/stdlib.h index 2162eaaa..a0d3b467 100644 --- a/porting/linux/user/include/fortify/stdlib.h +++ b/porting/linux/user/include/fortify/stdlib.h @@ -26,7 +26,7 @@ extern "C" { #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), PATH_MAX), +__DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS(resolved), FORTIFY_PATH_MAX), "'realpath' " OUTPUT_PARAMETER_BYTES); #endif #ifdef __cplusplus diff --git a/porting/linux/user/include/fortify/unistd.h b/porting/linux/user/include/fortify/unistd.h index f9e150e9..39d0a5b8 100644 --- a/porting/linux/user/include/fortify/unistd.h +++ b/porting/linux/user/include/fortify/unistd.h @@ -26,15 +26,15 @@ extern "C" { #if defined(__FORTIFY_COMPILATION) #define __DIAGNOSE_ERROR_IF_OVERFLOWS_SSIZET(what, fn) \ - __DIAGNOSE_ERROR_IF((what) > SSIZE_MAX, "in call to '" #fn "', '" #what "' must be <= SSIZE_MAX") + __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) <= (SSIZE_MAX)) && \ - __builtin_constant_p(index) && (index) <= (SSIZE_MAX))) + ((__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) ; diff --git a/porting/linux/user/src/fortify/fortify.c b/porting/linux/user/src/fortify/fortify.c index 12121715..5804a55e 100644 --- a/porting/linux/user/src/fortify/fortify.c +++ b/porting/linux/user/src/fortify/fortify.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include diff --git a/scripts/runtest.sh b/scripts/runtest.sh index 8e3e47b1..88dce0f4 100755 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -22,6 +22,8 @@ do do if [ "$(FileSuffix ${file})" = "so" ] \ || [ "$file" = "trace_stresstest" ] \ + || [ "$file" = "fatal_message" ] \ + || [ "$file" = "tgkill" ] \ || [ -d ./$subdir/$file ] then continue diff --git a/scripts/runtest_Windows.bat b/scripts/runtest_Windows.bat index 6fc3d7b9..472f623e 100644 --- a/scripts/runtest_Windows.bat +++ b/scripts/runtest_Windows.bat @@ -105,7 +105,7 @@ hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/inherit_030 hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/inherit_0700.so hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/inherit_0800.so hdc shell cp %REMOTEFEXT%/dlns/libdlopen_ns_dso.so %REMOTEFEXT%/dlns/inherit_1100.so -hdc shell mv /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-temp.ini +hdc shell cp /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-temp.ini hdc shell mv /etc/ld-musl-namespace-arm-test.ini /etc/ld-musl-namespace-arm.ini @@ -136,9 +136,9 @@ echo The test cases have been executed. @REM 恢复现场 echo Start restore the scene -echo hdc shell mv /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-test.inherit_0300 +echo hdc shell mv /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-test.ini echo ... -hdc shell mv /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-test.ini +hdc shell cp /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm-test.ini hdc shell mv /etc/ld-musl-namespace-arm-temp.ini /etc/ld-musl-namespace-arm.ini hdc shell rm %REMOTEFEXT%/dlns/sharedlibtest.so -rf hdc shell rm %REMOTEFEXT%/dlns/B/libB.so -rf -- GitLab