From d54203789b45badfa9a4b38474d8f46a1cb006c1 Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Wed, 29 Dec 2010 19:31:00 +0000 Subject: [PATCH] Added dumbledore and dumbledore_cmd examples for testing concolic engine. --- .gitattributes | 2 ++ examples/Makefile | 11 +++++++++- examples/dumbledore.c | 45 ++++++++++++++++++++++++++++++++++++++ examples/dumbledore_cmd.c | 46 +++++++++++++++++++++++++++++++++++++++ tools/do_concolic.sh | 19 +++++++++++++++- 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 examples/dumbledore.c create mode 100644 examples/dumbledore_cmd.c diff --git a/.gitattributes b/.gitattributes index 96303a5cb..55fee17bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,6 +6,8 @@ examples/Makefile -text examples/block_copy.c -text examples/cmd_args_005.c -text examples/concolic_test_handshake.c -text +examples/dumbledore.c -text +examples/dumbledore_cmd.c -text examples/fptest.c -text examples/globalfield.c -text examples/hanoi.c -text diff --git a/examples/Makefile b/examples/Makefile index ef365305f..7ed52a8e6 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -162,6 +162,14 @@ cmd_args_005: cmd_args_005.o ${STRATA}/lib/x86_linux/libstrata_normal.a .PHONY ${PEASOUP_HOME}/tools/peasoup_link++ cmd_args_005.o -o cmd_args_005 ${SMPSA_HOME}/SMP-analyze.sh cmd_args_005.ncexe +dumbledore: dumbledore.o ${STRATA}/lib/x86_linux/libstrata_normal.a .PHONY + ${PEASOUP_HOME}/tools/peasoup_link++ dumbledore.o -o dumbledore + ${SMPSA_HOME}/SMP-analyze.sh dumbledore.ncexe + +dumbledore_cmd: dumbledore_cmd.o ${STRATA}/lib/x86_linux/libstrata_normal.a .PHONY + ${PEASOUP_HOME}/tools/peasoup_link++ dumbledore_cmd.o -o dumbledore_cmd + ${SMPSA_HOME}/SMP-analyze.sh dumbledore_cmd.ncexe + .PHONY: env_check .c.o: @@ -199,10 +207,11 @@ double_free_suite: cd double_free_tests; make clean: - rm -f *.o *.syms *.map chopzero hanoi hanoi_overrun hanoi_heap_overrun malloc block_copy print_ptr hanoi_stack_overrun + rm -f *.o *.syms *.map chopzero hanoi hanoi_overrun hanoi_heap_overrun malloc block_copy print_ptr hanoi_stack_overrun dumbledore a.out memcpy hanoi_overrun_taintedenv dumbledore_cmd hanoi_overrun_tainted hello cmd_args_005 rm -f *.exe *.dis *.data *.idb *.log *.ncexe *.annot *.readelf temp.* *.temp *.stratafied *.asm *.SMPobjdump *.id0 *.id1 *.til *.nam rm -Rf concolic.files_* rm -f strata.log.* + rm -f *.sym concclean: rm -Rf concolic.files_* diff --git a/examples/dumbledore.c b/examples/dumbledore.c new file mode 100644 index 000000000..39951a5b7 --- /dev/null +++ b/examples/dumbledore.c @@ -0,0 +1,45 @@ + +#include <stdio.h> +#include <sys/mman.h> +#include <string.h> +#include <stdlib.h> + +enum {BUFSIZE = 98}; + +char grade = 'D'; +char Name[BUFSIZE]; +FILE *f; + +void readString(char *s) { + char buf[BUFSIZE]; + int i = 0; + int c; + + for (;;) + { + c = getchar(); + if ((c == EOF) || (c == '\n')) + break; + buf[i] = c; + i++; + } + buf[i] = '\0'; + + for (i = 0; i < BUFSIZE; i++) + s[i] = buf[i]; +} + + +int main(void) +{ + readString(Name); + + if (strcmp(Name, "Wizard in Training") == 0) + grade = 'B'; + + printf("Thank you, %s.\n", Name); + printf("I recommend that you get a grade of %c on this assignment.\n", grade); + + exit(0); +} + diff --git a/examples/dumbledore_cmd.c b/examples/dumbledore_cmd.c new file mode 100644 index 000000000..8b9ddd611 --- /dev/null +++ b/examples/dumbledore_cmd.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <sys/mman.h> +#include <string.h> +#include <stdlib.h> + +enum {BUFSIZE = 24}; + +char grade = 'D'; +char Name[BUFSIZE]; + +void readString(char *in, char *s) { + char buf[BUFSIZE]; + int i = 0; + int c; + + for (;;) + { + c = in[i]; + if ((c == '\0') || (c == '\n')) + break; + + buf[i] = c; + i++; + } + buf[i] = '\0'; + + for (i = 0; i < BUFSIZE; i++) + s[i] = buf[i]; +} + + +int main(int argc, char * argv[]) +{ + if (argc == 2) + readString(argv[1], Name); + + if (strcmp(Name, "Wizard in Training") == 0) + grade = 'B'; + + printf("Thank you, %s.\n", Name); + printf("I recommend that you get a grade of %c on this assignment.\n", grade); + + return 0; +} + + diff --git a/tools/do_concolic.sh b/tools/do_concolic.sh index a306760c3..b6806b648 100755 --- a/tools/do_concolic.sh +++ b/tools/do_concolic.sh @@ -5,9 +5,19 @@ shift extra_args=$* strata_exe=$exe.stratafied annot=$exe.ncexe.annot +sym=$exe.sym whoami=`whoami` +# +# simple error checking +# +if [ $GRACE_HOME"X" = "X" ]; then echo Failed to set GRACE_HOME; exit 2; fi +if [ ! -f $GRACE_HOME/concolic/src/util/linux/meds_annot_to_grace ]; then + echo "Failed to set GRACE_HOME properly (i.e. wrong path)" + exit 3 +fi + # get a starting pc line=`cat $annot|egrep " FUNC GLOBAL main"|sed "s/ */ /g"` @@ -17,12 +27,19 @@ start_ea=`echo $line |cut -d" " -f1` line=`cat $annot|egrep " FUNC GLOBAL exit"|sed "s/ */ /g"` stop_ea=`echo $line |cut -d" " -f1` +# assume grace_home env is set. +$GRACE_HOME/concolic/src/util/linux/meds_annot_to_grace $annot +if [ ! -f $sym ]; then + echo Failed to produce .sym file + exit 1; +fi + echo Removing all ipc queues. for i in `ipcs -q|grep $whoami |cut -d" " -f 2`; do ipcrm -q $i done -STRATA_GRACE=1 controller $extra_args --start $start_ea --stop $stop_ea $strata_exe +STRATA_GRACE=1 controller $extra_args --start $start_ea --stop $stop_ea $strata_exe --symbols $sym echo cleaning up killall -q controller -- GitLab