From bfc6f3796ea9e518415e8f9038b0cbc54f1587d8 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 27 Jul 2020 16:29:43 -0400 Subject: [PATCH 1/5] build: Add an 80386-only mode --- CMakeLists.txt | 4 ++++ build.sh | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b8f091f8..44b351629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ else(WIN32) -m32 ) + if(ONLY_80386) + add_compile_options(-march=i386) + endif(ONLY_80386) + # Link everything 32-bit (until we have a 64-bit option) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") diff --git a/build.sh b/build.sh index 7c94cf4a2..46a33960e 100755 --- a/build.sh +++ b/build.sh @@ -25,6 +25,16 @@ CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" CC=${CC:-clang} CXX=${CXX:-clang++} +if [[ -n "${ONLY_80386}" ]]; then + # NOTE(ww): clang's -march=i386 generates instructions for i486 and i586. + # See: https://reviews.llvm.org/D18802 (which was never merged) + if [[ "${CC}" == "clang" ]]; then + echo "80386-only instructions requested, but clang has a buggy -march=i386. Good luck!" + fi + + CMAKE_OPTS="$CMAKE_OPTS -DONLY_80386=1" +fi + CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_C_COMPILER=$CC" CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_ASM_COMPILER=$CC" CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_CXX_COMPILER=$CXX" From 97fb51d815a3781a3f3d878c935b7effe2af1376 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 27 Jul 2020 16:41:35 -0400 Subject: [PATCH 2/5] challenges: Use -Os instead of -Oz --- challenges/Azurad/CMakeLists.txt | 2 +- challenges/FailAV/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/challenges/Azurad/CMakeLists.txt b/challenges/Azurad/CMakeLists.txt index 3a35022bd..8501ae3b2 100644 --- a/challenges/Azurad/CMakeLists.txt +++ b/challenges/Azurad/CMakeLists.txt @@ -1,6 +1,6 @@ add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) set( SERVICE_ID "00119" ) set( AUTHOR_ID "KPRCA" ) -add_compile_options( -Oz -g ) +add_compile_options( -Os -g ) set( VULN_COUNT "1" ) buildCB() diff --git a/challenges/FailAV/CMakeLists.txt b/challenges/FailAV/CMakeLists.txt index ed717c236..aafd87829 100644 --- a/challenges/FailAV/CMakeLists.txt +++ b/challenges/FailAV/CMakeLists.txt @@ -1,7 +1,7 @@ set( VULN_COUNT "1" ) add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS ) set( override LDFLAGS "-nostdlib -static -Ttext=0x90000000" ) -add_compile_options( -Oz -g ) +add_compile_options( -Os -g ) set( SERVICE_ID "00091" ) set( AUTHOR_ID "KPRCA" ) buildCB() From 89c60ebafb5756e366f833dd7d3190e08426c247 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 27 Jul 2020 16:54:05 -0400 Subject: [PATCH 3/5] challenges/Blubber: Rename variable to satiate GCC --- challenges/Blubber/cb_1/src/server.cc | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/challenges/Blubber/cb_1/src/server.cc b/challenges/Blubber/cb_1/src/server.cc index f9a4a3c46..189e7c989 100644 --- a/challenges/Blubber/cb_1/src/server.cc +++ b/challenges/Blubber/cb_1/src/server.cc @@ -48,7 +48,7 @@ typedef struct bool registered; bool waiting; uint32_t last_read; - blubber* blubber; + blubber* blubber_; } client_state; client_state* new_client(int n) @@ -73,7 +73,7 @@ client_state* new_client(int n) c->last_read = 0; c->registered = false; - c->blubber = new blubber(); + c->blubber_ = new blubber(); return c; } @@ -128,11 +128,11 @@ void handle_read(server_state* s, client_state* c) for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; - if (c->blubber->subs.contains(other->blubber)) + if (c->blubber_->subs.contains(other->blubber_)) { - for (cgc_size_t j = 0; j < other->blubber->blubs.length(); j++) + for (cgc_size_t j = 0; j < other->blubber_->blubs.length(); j++) { - blub* b = (blub*)other->blubber->blubs.get(j); + blub* b = (blub*)other->blubber_->blubs.get(j); if (b->ts > c->last_read) { unread.add(b); @@ -169,11 +169,11 @@ void handle_blub(client_state* c) tmp[BLUB_MAX] = '\0'; dbg("Recorded blub (%s) %d", tmp, cgc_strlen(tmp)) - c->blubber->record_blub(tmp); + c->blubber_->record_blub(tmp); } else { - blub* b = c->blubber->gen_blub(); + blub* b = c->blubber_->gen_blub(); if (b) { dbg("Recorded blub (%s) %d", b->content, cgc_strlen(b->content)); @@ -202,23 +202,23 @@ void handle_reblub(server_state* s, client_state* c) idx = cgc_strtol(num, NULL, 10); - dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber->username, username, idx); + dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber_->username, username, idx); for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; // Make sure author exists and client is subbed to them. - if (cgc_strcmp(other->blubber->username, username) == 0 && c->blubber->subs.contains(other->blubber)) + if (cgc_strcmp(other->blubber_->username, username) == 0 && c->blubber_->subs.contains(other->blubber_)) { - dbg("Found (%s) in (%s)'s subs", other->blubber->username, c->blubber->username); - if (other->blubber->blubs.length() > idx) + dbg("Found (%s) in (%s)'s subs", other->blubber_->username, c->blubber_->username); + if (other->blubber_->blubs.length() > idx) { - dbg("Fetching (%s) %d blub", other->blubber->username, idx); - blub* b = (blub*)other->blubber->blubs.get(idx); + dbg("Fetching (%s) %d blub", other->blubber_->username, idx); + blub* b = (blub*)other->blubber_->blubs.get(idx); if (b) { - dbg("(%s) reblubbed (%s)'s %d blub", c->blubber->username, other->blubber->username, idx); - blub* n = new blub(c->blubber->username, b->content); - c->blubber->blubs.add(n); + dbg("(%s) reblubbed (%s)'s %d blub", c->blubber_->username, other->blubber_->username, idx); + blub* n = new blub(c->blubber_->username, b->content); + c->blubber_->blubs.add(n); } } } @@ -235,26 +235,26 @@ void handle_sub(server_state* s, client_state* c) } username[USERNAME_MAX] = '\0'; - dbg("Attempting to sub (%s) to (%s)", c->blubber->username, username); + dbg("Attempting to sub (%s) to (%s)", c->blubber_->username, username); for (cgc_size_t i = 0; i < s->num_clients; ++i) { client_state* other = s->clients[i]; - if (cgc_strcmp(other->blubber->username, username) == 0) + if (cgc_strcmp(other->blubber_->username, username) == 0) { - if (c->blubber->subs.contains(other->blubber)) + if (c->blubber_->subs.contains(other->blubber_)) { - dbg("(%s) is already subbed to (%s)", c->blubber->username, username); + dbg("(%s) is already subbed to (%s)", c->blubber_->username, username); return; } else { - dbg("Subbed (%s) to (%s)", c->blubber->username, username); - c->blubber->subs.add(other->blubber); + dbg("Subbed (%s) to (%s)", c->blubber_->username, username); + c->blubber_->subs.add(other->blubber_); return; } } } - dbg("Failed to sub (%s) to (%s)", c->blubber->username, username); + dbg("Failed to sub (%s) to (%s)", c->blubber_->username, username); } int run_server(server_state* state) @@ -275,7 +275,7 @@ int run_server(server_state* state) dbg("Registered %d as (%s)", c->n, username); cgc_fprintf(c->tx, (char *)"Welcome to blubber, %s" EOT_S, username); c->registered = true; - c->blubber->set_username(username); + c->blubber_->set_username(username); state->num_alive++; } From 24ee8ee04312c9358d54f38cc4fb3e5954c5b63c Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 27 Jul 2020 17:07:09 -0400 Subject: [PATCH 4/5] CMakeLists: Add -fpermissive when building with gcc --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44b351629..00911ebae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,12 @@ else(WIN32) add_compile_options(-march=i386) endif(ONLY_80386) + if(CMAKE_C_COMPILER EQUAL "gcc") + # NOTE(ww): Recent versions of GCC are more strict than Clang about + # nonsensical C/C++ constructs, some of which are present in the challenges. + add_compile_options(-fpermissive) + endif(CMAKE_C_COMPILER EQUAL "gcc") + # Link everything 32-bit (until we have a 64-bit option) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") From 07126a8eed7832733abbcd9a39f666a0d3b029e8 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 27 Jul 2020 17:16:59 -0400 Subject: [PATCH 5/5] Revert "CMakeLists: Add -fpermissive when building with gcc" This reverts commit 24ee8ee04312c9358d54f38cc4fb3e5954c5b63c. --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00911ebae..44b351629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,12 +64,6 @@ else(WIN32) add_compile_options(-march=i386) endif(ONLY_80386) - if(CMAKE_C_COMPILER EQUAL "gcc") - # NOTE(ww): Recent versions of GCC are more strict than Clang about - # nonsensical C/C++ constructs, some of which are present in the challenges. - add_compile_options(-fpermissive) - endif(CMAKE_C_COMPILER EQUAL "gcc") - # Link everything 32-bit (until we have a 64-bit option) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")