From 5d8e0614382c2fb089939f93cef7201ce3ad4776 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 08:45:24 -0800 Subject: [PATCH] Add make test rule to 2012/zeitak + formatting The make test rule runs the new test.sh script which checks the return value of the program run on a variety of new files (and the old incorrect.c which was renamed incorrect.paren.c). The new files include 1984/anonymous.c and 1984/anonymous.alt.c as the author explicitly mentioned that entry. The README.md file has been format/typo checked. --- 2012/zeitak/Makefile | 6 +- 2012/zeitak/README.md | 36 ++-- 2012/zeitak/anonymous.alt.c | 2 + 2012/zeitak/anonymous.c | 2 + 2012/zeitak/incorrect.1.quote.c | 7 + 2012/zeitak/incorrect.3.quotes.c | 7 + 2012/zeitak/incorrect.brace.c | 7 + 2012/zeitak/incorrect.bracket.c | 7 + .../zeitak/{incorrect.c => incorrect.paren.c} | 14 +- 2012/zeitak/incorrect.quote-esc.c | 7 + 2012/zeitak/incorrect.single.quote.c | 7 + 2012/zeitak/incorrect.txt | 1 + 2012/zeitak/test.sh | 161 ++++++++++++++++++ thanks-for-fixes.md | 9 + 14 files changed, 251 insertions(+), 22 deletions(-) create mode 100644 2012/zeitak/anonymous.alt.c create mode 100644 2012/zeitak/anonymous.c create mode 100644 2012/zeitak/incorrect.1.quote.c create mode 100644 2012/zeitak/incorrect.3.quotes.c create mode 100644 2012/zeitak/incorrect.brace.c create mode 100644 2012/zeitak/incorrect.bracket.c rename 2012/zeitak/{incorrect.c => incorrect.paren.c} (92%) create mode 100644 2012/zeitak/incorrect.quote-esc.c create mode 100644 2012/zeitak/incorrect.single.quote.c create mode 100644 2012/zeitak/incorrect.txt create mode 100755 2012/zeitak/test.sh diff --git a/2012/zeitak/Makefile b/2012/zeitak/Makefile index 4ddf0734b..05f9d3081 100644 --- a/2012/zeitak/Makefile +++ b/2012/zeitak/Makefile @@ -113,7 +113,7 @@ ENTRY= zeitak PROG= ${ENTRY} # OBJ= ${PROG}.o -DATA= incorrect.c +DATA= incorrect.paren.c incorrect.brace.c incorrect.bracket.c TARGET= ${PROG} # ALT_OBJ= ${PROG}.alt.o @@ -135,6 +135,10 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +test: test.sh + ./$< || exit 1 + + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2012/zeitak/README.md b/2012/zeitak/README.md index a3f6ffa7e..d9788050b 100644 --- a/2012/zeitak/README.md +++ b/2012/zeitak/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version that is slightly deobfuscated. See [alternate +code](#alternate-code) below. + ## To use: @@ -18,8 +21,7 @@ try [incorrect.c](incorrect.c) and the program itself. ### Try: ```sh -./zeitak < zeitak.c -./zeitak < incorrect.c +make test ``` NOTE: it prints an error and exits on the first nesting error so it will not @@ -28,17 +30,19 @@ detect multiple issues! ## Alternate code: -An alternate version of this entry, [zeitak.alt.c](zeitak.alt.c), is provided. -The file [zeitak.alt.c](zeitak.alt.c) provides a version that has been slightly -deobfuscated. You may find reading that file helpful in your attempt -to understand this extremely subtle entry. +This version, [zeitak.alt.c](zeitak.alt.c), is a version that has been slightly +deobfuscated. You may find reading it helpful in your attempt to understand +this extremely subtle entry. -To compile this alternate version: + +### Alternate build: ```sh make alt ``` +### Alternate use: + Use `zeitak.alt` as you would `zeitak` above. @@ -55,8 +59,10 @@ just to understand 18 key characters of this code. ## Author's remarks: + ### Nesting Errors Detector + #### What does it do As you have probably understood by looking at the source\*, this program has @@ -69,7 +75,8 @@ If an error is detected, an error message will be printed. If the problem is a superfluous closing bracket, it will even print a few characters around it's position. -* Make sure you view the source with 4 spaces tab width. +\* Make sure you view the source with 4 spaces tab width. + #### Features @@ -99,7 +106,7 @@ even more limited source, that is: * Without any digits. * Without any character constants. -* Without using functions from headers other than stdio. +* Without using functions from headers other than `stdio`. * Without any control-flow keywords (not even the `?:` operator). * Without any arithmetic or logic operators! @@ -107,7 +114,8 @@ So, what's left? Parenthesis, and lots of them, as looking at the source will reveal immediately. The main obfuscation is building the whole algorithm using only function calls, typecasts, array lookups and pointer operators. -##### Additional obfuscations include: + +#### Additional obfuscations include: * Extensive reuse of identifiers: Macros share names with variables, inner curly braces scopes contain variables with names identical to those in the @@ -117,16 +125,16 @@ only function calls, typecasts, array lookups and pointer operators. * Mostly one-letter identifiers. * Complex recursion: A function might call itself once, twice, or not at all. + #### Compilation/Portability/Running Notes * The program requires `char` to be one byte and pointers to be at least two bytes long. * The program was tested on the following platforms: - -- Ubuntu 9.04 32-bit with GCC -- Windows 7 32-bit with GCC -- Windows 7 32-bit with OpenWatcom + - Ubuntu 9.04 32-bit with GCC + - Windows 7 32-bit with GCC + - Windows 7 32-bit with OpenWatcom ## Copyright and CC BY-SA 4.0 License: diff --git a/2012/zeitak/anonymous.alt.c b/2012/zeitak/anonymous.alt.c new file mode 100644 index 000000000..a8681d1e5 --- /dev/null +++ b/2012/zeitak/anonymous.alt.c @@ -0,0 +1,2 @@ +int i;main(){for(;i["] + +int main() { + int i=40; + printf("); + return 0; +} diff --git a/2012/zeitak/incorrect.3.quotes.c b/2012/zeitak/incorrect.3.quotes.c new file mode 100644 index 000000000..017356404 --- /dev/null +++ b/2012/zeitak/incorrect.3.quotes.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf("""); + return 0; +} diff --git a/2012/zeitak/incorrect.brace.c b/2012/zeitak/incorrect.brace.c new file mode 100644 index 000000000..619c29db6 --- /dev/null +++ b/2012/zeitak/incorrect.brace.c @@ -0,0 +1,7 @@ +#include + +int main() {}} + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.bracket.c b/2012/zeitak/incorrect.bracket.c new file mode 100644 index 000000000..e35e8e795 --- /dev/null +++ b/2012/zeitak/incorrect.bracket.c @@ -0,0 +1,7 @@ +#include + +int main() ]] }} + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.c b/2012/zeitak/incorrect.paren.c similarity index 92% rename from 2012/zeitak/incorrect.c rename to 2012/zeitak/incorrect.paren.c index 3fc09c23d..c3f00e123 100644 --- a/2012/zeitak/incorrect.c +++ b/2012/zeitak/incorrect.paren.c @@ -1,7 +1,7 @@ -#include - -int main() { - int i=40; - printf("%c",(char)(i))); - return 0; -} +#include + +int main() { + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.quote-esc.c b/2012/zeitak/incorrect.quote-esc.c new file mode 100644 index 000000000..cc4274a14 --- /dev/null +++ b/2012/zeitak/incorrect.quote-esc.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf("\""); + return 0; +} diff --git a/2012/zeitak/incorrect.single.quote.c b/2012/zeitak/incorrect.single.quote.c new file mode 100644 index 000000000..53c1ca617 --- /dev/null +++ b/2012/zeitak/incorrect.single.quote.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf('); + return 0; +} diff --git a/2012/zeitak/incorrect.txt b/2012/zeitak/incorrect.txt new file mode 100644 index 000000000..1cc80efa6 --- /dev/null +++ b/2012/zeitak/incorrect.txt @@ -0,0 +1 @@ +" diff --git a/2012/zeitak/test.sh b/2012/zeitak/test.sh new file mode 100755 index 000000000..756ebe262 --- /dev/null +++ b/2012/zeitak/test.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/zeitak +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +# assume no error: set ERROR to 0 +ERROR=0 + +read -r -n 1 -p "Press any key to test zeitak.c for nesting errors: " +echo 1>&2 +./zeitak < zeitak.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat anonymous.c" 1>&2 +cat anonymous.c +echo 1>&2 +read -r -n 1 -p "Press any key to test anonymous.c for nesting errors: " +echo 1>&2 +./zeitak < anonymous.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat anonymous.alt.c" 1>&2 +cat anonymous.alt.c +echo 1>&2 +read -r -n 1 -p "Press any key to test anonymous.alt.c for nesting errors: " +echo 1>&2 +./zeitak < anonymous.alt.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.brace.c" 1>&2 +cat incorrect.brace.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.brace.c: " +echo 1>&2 +./zeitak < incorrect.brace.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.bracket.c" 1>&2 +cat incorrect.bracket.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.bracket.c: " +echo 1>&2 +./zeitak < incorrect.bracket.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.paren.c" 1>&2 +cat incorrect.paren.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.paren.c: " +echo 1>&2 +./zeitak < incorrect.paren.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.quote-esc.c" 1>&2 +cat incorrect.quote-esc.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.quote-esc.c: " +echo 1>&2 +./zeitak < incorrect.quote-esc.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.3.quotes.c" 1>&2 +cat incorrect.3.quotes.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.3.quotes.c: " +echo 1>&2 +./zeitak < incorrect.3.quotes.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.single.quote.c" 1>&2 +cat incorrect.single.quote.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.single.quote.c: " +echo 1>&2 +./zeitak < incorrect.single.quote.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.1.quote.c" 1>&2 +cat incorrect.1.quote.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.1.quote.c: " +echo 1>&2 +./zeitak < incorrect.1.quote.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.txt" 1>&2 +cat incorrect.txt +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.txt: " +echo 1>&2 +./zeitak < incorrect.txt +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +exit "$ERROR" diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 92075cd96..d09d97b16 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3382,6 +3382,15 @@ We're not sure whether we want to thank Cody or not for this :-) and he's not sure if he wants to be thanked either :-) but we appreciate it nonetheless. +## [2012/zeitak](2012/zeitak/zeitak.c) ([README.md](2012/zeitak/README.md])) + +Cody added the `make test` rule and the [test.sh](2012/zeitak/test.sh) along +with a number of files that will be correctly be flagged as incorrect (including +a text file to show that it's not that it parses C but rather just matching +pairs though that should be obvious) and also some that are correct including +1984/anonymous (as the author explicitly mentioned it). + + # 2013