Commit af0cf8c2 authored by Andre Maroneze's avatar Andre Maroneze 💬
Browse files

Merge branch 'infer/bench_moerman' into 'master'

Infer/bench moerman

See merge request !5
parents ae96f56e fe5e4dcf
......@@ -52,6 +52,7 @@ frama-c/build/bin/frama-c:
TARGETS=\
2048 \
basic-cwe-examples \
bench-moerman2018 \
cerberus \
chrony \
debie1 \
......
......@@ -120,6 +120,7 @@ when available. We also summarize the license of each directory below.
- `2048`: MIT
- `basic-cwe-examples`: see `LICENSE`
- `bench-moerman2018`: MIT
- `chrony`: GPL
- `debie1`: distribution and use authorized by Patria Aviation Oy,
Space Systems Finland Ltd. and Tidorum Ltd, see `README.txt`
......
# extra .gitignore rules specific to this benchmark
# we do not version the .parse and .eva directories due to their large size
eval.txt
*.eva
*.parse
# Makefile template for Frama-C/Eva case studies.
# For details and usage information, see the Frama-C User Manual.
### Prologue. Do not modify this block. #######################################
-include path.mk
FRAMAC ?= frama-c
include $(shell $(FRAMAC)-config -scripts)/prologue.mk
###############################################################################
# Edit below as needed. MACHDEP is mandatory. Suggested flags are optional.
MACHDEP = x86_32
## Preprocessing flags (for -cpp-extra-args)
CPPFLAGS += \
-I../common \
## General flags
FCFLAGS += \
-add-symbolic-path=.:.. \
-kernel-warn-key annot:missing-spec=abort \
-kernel-warn-key typing:implicit-function-declaration=abort \
## Eva-specific flags
EVAFLAGS += \
-eva-warn-key builtins:missing-spec=abort \
-eva-precision 3 \
## GUI-only flags
FCGUIFLAGS += \
-add-symbolic-path=.:.. \
# This bench has several targets, so we use Makefile functions to generate
# them. A few test cases are not run.
# exclude files with recursive functions, and those testing memory leaks
filter-out-substring = $(foreach v,$(2),$(if $(findstring $(1),$(v)),,$(v)))
SRCS:=$(sort $(call filter-out-substring,leak,\
$(call filter-out-substring,recursion,\
$(wildcard ../base/*.c ../*/*/*.c))))
# [target] converts a file name into a suitable target name,
# removing the initial '../', the final '.c', and converting '/' into '_'.
target = $(subst /,_,$(patsubst %.c,%,$(1:../%=%)))
GOOD_TARGETS:=$(foreach s,$(SRCS),$(call target,$(s))_good.eva)
BAD_TARGETS:=$(foreach s,$(SRCS),$(call target,$(s))_bad.eva)
TARGETS:=$(GOOD_TARGETS) $(BAD_TARGETS)
define generate-parse-rules =
$(call target,$(1))_good.parse: $(if $(findstring cross_file,$(1)),../common/common.c,) $(1)
$(call target,$(1))_good.parse: CPPFLAGS+="-DNO_BUG"
$(call target,$(1))_bad.parse: $(if $(findstring cross_file,$(1)),../common/common.c,) $(1)
$(call target,$(1))_good.eva/eval.txt: $(call target,$(1))_good.eva evaluate_case.sh
./evaluate_case.sh good $$</alarms.csv > $$</eval.txt
$(call target,$(1))_bad.eva/eval.txt: $(call target,$(1))_bad.eva evaluate_case.sh
./evaluate_case.sh bad $$</alarms.csv > $$</eval.txt
endef
$(foreach s,$(SRCS),$(eval $(call generate-parse-rules,$(s))))
eval_summary.txt: $(addsuffix /eval.txt, $(TARGETS))
@echo "Updating summary: $(abspath $@)"
@cat $^ > eval_summary.txt
evaluate: eval_summary.txt
.PHONY: eval_summary.txt
all: evaluate
### Epilogue. Do not modify this block. #######################################
include $(shell $(FRAMAC)-config -scripts)/epilogue.mk
###############################################################################
# optional, for OSCS
-include ../../Makefile.common
This diff is collapsed.
#!/bin/bash -eu
if [ $# -lt 2 ]; then
echo "usage: $0 (good|bad) path/to/alarms.csv"
exit 1
fi
goodbad="$1"
alarms=$(wc -l "$2" | cut -d' ' -f1)
case $goodbad in
"good")
if [ "$alarms" -gt 1 ]; then
echo "$2 ($goodbad): imprecise"
else
echo "$2 ($goodbad): ok"
fi
;;
"bad")
if [ "$alarms" -lt 2 ]; then
echo "$2 ($goodbad): unsound"
else
echo "$2 ($goodbad): ok"
fi
;;
*)
echo "invalid '$goodbad': must be either 'good' or 'bad'."
exit 1
esac
../../path.mk
\ No newline at end of file
MIT License
Copyright (c) 2018 Jonathan Moerman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# About this test suite
This test suite was designed and used for my bachelor thesis "Evaluating the performance of open source static analysis tools".
This test suite was inspired by, and used in conjunction with the test suite presented in "Test-driving static analysis tools in search of c code vulnerabilities" by George Chatzieleftheriou and Panagiotis Katsaros.
## How to use this test suite
The .c files included in this test suite need to be preprocessed before use. The shellscript ```preprocess_files.sh``` can be used to accomplish this.
- ```preprocess_files.sh``` needs a unix like environment with gpp installed to work.
- Usage: ```preprocess_files.sh [directory to process]```, for example ```preprocess_files.sh ./integers/overflow/```.
This should generate the sub directories ```test_correct``` (safe calls to unsafe functions), ```test_incorrect``` (unsafe calls to unsafe functions), ```test_lib_correct``` (safe functions, no entry point), ```test_lib_incorrect``` (unsafe functions, no entry point) and ```test_correct_catch_bad``` (safe calls to safe functions).
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE* file;
file = fopen("file.txt","r");
if(!file) {
return 0;
}
#ifdef NO_BUG
printf("%i\n", (int) fgetc(file));
fclose(file);
#else
fclose(file);
printf("%i\n", (int) fgetc(file));
#endif
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE* file;
file = fopen("file.txt","r");
if(!file) {
return 1;
}
printf("%i\n", (int) fgetc(file));
#ifdef NO_BUG
fclose(file);
#else
fclose(file);
fclose(file);
#endif
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE* file;
file = fopen("file.txt","r");
if(!file) {
return 1;
}
printf("%i\n", (int) fgetc(file));
#ifdef NO_BUG
fclose(file);
#endif
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int x;
#ifdef NO_BUG
x = 1;
#else
x = 0;
#endif
printf("%i\n", 5 / x);
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int arr[3] = {1, 2, 3};
int* ptr;
#ifdef NO_BUG
ptr = arr;
#else
ptr = 0;
#endif
printf("%i\n", *ptr + arr[2]);
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int arr[3] = {1, 2, 3};
int* ptr;
#ifdef NO_BUG
ptr = arr;
#endif
printf("%i\n", *ptr + arr[2]);
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int x;
#ifdef NO_BUG
x = 5;
#endif
printf("%i\n", x + 1);
return 1;
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int x;
#ifdef NO_BUG
x = INT_MAX - 1;
#else
x = INT_MAX;
#endif
printf("%i\n", x + 1);
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int* data;
int x = 33;
data = malloc(5 * sizeof(int));
if(!data) {
return -1;
}
*data = x;
printf("%i\n", *data);
free(data);
#ifndef NO_BUG
free(data);
#endif
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int* data;
int x = 33;
data = malloc(5 * sizeof(int));
if(!data) {
return -1;
}
*data = x;
printf("%i\n", *data);
#ifdef NO_BUG
free(data);
#endif
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int* data;
data = malloc(sizeof(int));
if(!data) {
return -1;
}
#ifdef NO_BUG
*data = 37;
#endif
printf("%i\n", *data);
free(data);
return 1;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment