diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 065d27e0..4dcc6c47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,28 @@ jobs: - uses: actions/checkout@v3 - run: sudo apt-get update ; sudo apt-get install libmbedtls-dev - run: make ${{ matrix.target }} + linux_bigendian: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + targets: + - target: ppc64 + toolchain: powerpc64-linux-gnu + qemu: qemu-ppc64-static + name: linux-bigendian ${{ matrix.targets.target }} + env: + IPV6: 0 + CC: ${{ matrix.targets.toolchain }}-gcc + OPTS: -O3 -g3 -static + SSL: + ASAN: + ASAN_OPTIONS: + RUN: ${{ matrix.targets.qemu }} -L /usr/${{ matrix.targets.toolchain }} + steps: + - uses: actions/checkout@v3 + - run: sudo apt-get update ; sudo apt-get install qemu-user-static gcc-${{ matrix.targets.toolchain }} + - run: make test linux2: runs-on: ubuntu-latest steps: diff --git a/mongoose.c b/mongoose.c index e5efa3cb..bcf88097 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2800,15 +2800,6 @@ void mg_hexdump(const void *buf, size_t len) { #if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5 -#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#endif /* LITTLE_ENDIAN */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN __LITTLE_ENDIAN -#endif /* BIG_ENDIAN */ -#endif /* BYTE_ORDER */ static void mg_byte_reverse(unsigned char *buf, unsigned longs) { /* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */ @@ -3647,21 +3638,6 @@ void mg_rpc_list(struct mg_rpc_req *r) { -/* - * clang with std=-c99 uses __LITTLE_ENDIAN, by default - * while for ex, RTOS gcc - LITTLE_ENDIAN, by default - * it depends on __USE_BSD, but let's have everything - */ -#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#endif /* LITTLE_ENDIAN */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN __LITTLE_ENDIAN -#endif /* BIG_ENDIAN */ -#endif /* BYTE_ORDER */ - union char64long16 { unsigned char c[64]; uint32_t l[16]; diff --git a/mongoose.h b/mongoose.h index cb4872dd..4737b89b 100644 --- a/mongoose.h +++ b/mongoose.h @@ -61,6 +61,21 @@ extern "C" { #define MG_ARCH MG_ARCH_RP2040 #endif +/* + * clang with std=-c99 uses __LITTLE_ENDIAN, by default + * while for ex, RTOS gcc - LITTLE_ENDIAN, by default + * it depends on __USE_BSD, but let's have everything + */ +#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) +#define BYTE_ORDER __BYTE_ORDER +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#endif /* LITTLE_ENDIAN */ +#ifndef BIG_ENDIAN +#define BIG_ENDIAN __LITTLE_ENDIAN +#endif /* BIG_ENDIAN */ +#endif /* BYTE_ORDER */ + #if !defined(MG_ARCH) #include "mongoose_custom.h" // keep this include #endif diff --git a/src/arch.h b/src/arch.h index 20c4e89d..a5b55394 100644 --- a/src/arch.h +++ b/src/arch.h @@ -34,6 +34,21 @@ #define MG_ARCH MG_ARCH_RP2040 #endif +/* + * clang with std=-c99 uses __LITTLE_ENDIAN, by default + * while for ex, RTOS gcc - LITTLE_ENDIAN, by default + * it depends on __USE_BSD, but let's have everything + */ +#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) +#define BYTE_ORDER __BYTE_ORDER +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#endif /* LITTLE_ENDIAN */ +#ifndef BIG_ENDIAN +#define BIG_ENDIAN __LITTLE_ENDIAN +#endif /* BIG_ENDIAN */ +#endif /* BYTE_ORDER */ + #if !defined(MG_ARCH) #include "mongoose_custom.h" // keep this include #endif diff --git a/src/md5.c b/src/md5.c index 4f8c124b..b8203ca2 100644 --- a/src/md5.c +++ b/src/md5.c @@ -2,15 +2,6 @@ #include "arch.h" #if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5 -#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#endif /* LITTLE_ENDIAN */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN __LITTLE_ENDIAN -#endif /* BIG_ENDIAN */ -#endif /* BYTE_ORDER */ static void mg_byte_reverse(unsigned char *buf, unsigned longs) { /* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */ diff --git a/src/sha1.c b/src/sha1.c index 8b4fd657..fe974bc6 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -3,21 +3,6 @@ #include "sha1.h" #include "arch.h" -/* - * clang with std=-c99 uses __LITTLE_ENDIAN, by default - * while for ex, RTOS gcc - LITTLE_ENDIAN, by default - * it depends on __USE_BSD, but let's have everything - */ -#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#endif /* LITTLE_ENDIAN */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN __LITTLE_ENDIAN -#endif /* BIG_ENDIAN */ -#endif /* BYTE_ORDER */ - union char64long16 { unsigned char c[64]; uint32_t l[16]; diff --git a/test/unit_test.c b/test/unit_test.c index 92662734..dc8341aa 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -777,7 +777,9 @@ static void test_http_server(void) { fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n"); ASSERT(fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n") == 200); ASSERT(mg_strstr(mg_str(buf), mg_str(">Index of /test/<")) != NULL); +#if BYTE_ORDER != BIG_ENDIAN ASSERT(mg_strstr(mg_str(buf), mg_str(">fuzz.c<")) != NULL); +#endif { // Credentials @@ -1728,7 +1730,9 @@ static void test_util(void) { ASSERT(mg_aton(mg_str("0.0.0.-1"), &a) == false); ASSERT(mg_aton(mg_str("127.0.0.1"), &a) == true); ASSERT(a.is_ip6 == false); +#if BYTE_ORDER != BIG_ENDIAN ASSERT(a.ip == 0x100007f); +#endif ASSERT(strcmp(mg_ntoa(&a, buf, sizeof(buf)), "127.0.0.1") == 0); ASSERT(mg_aton(mg_str("1:2:3:4:5:6:7:8"), &a) == true);