Skip to content

Commit e12afc2

Browse files
authored
Merge pull request diffblue#188 from diffblue/pull-support-20170908
Pull security-scanner-support into subtree
2 parents b30420e + 3b0854c commit e12afc2

File tree

1,439 files changed

+31350
-7286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,439 files changed

+31350
-7286
lines changed

.travis.yml

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,68 @@
11
language: cpp
22

3-
matrix:
3+
jobs:
44
include:
55

6-
# LOCAL CHANGES: Added CBMC_ALPINE_BUILD so that regression tests (which require Python) can be skipped in this case.
7-
# We really only care about breaking core cbmc in this case anyhow.
6+
# LOCAL CHANGES: added cbmc/ prefix to both these scripts
7+
8+
- &linter-stage
9+
stage: Linter + Doxygen + non-debug Ubuntu/gcc-5 test
10+
env: NAME="CPP-LINT"
11+
install:
12+
script: cbmc/scripts/travis_lint.sh
13+
before_cache:
14+
15+
- &doxygen-stage
16+
stage: Linter + Doxygen + non-debug Ubuntu/gcc-5 test
17+
env: NAME="DOXYGEN-CHECK"
18+
addons:
19+
apt:
20+
packages:
21+
- doxygen
22+
install:
23+
script: cbmc/scripts/travis_doxygen.sh
24+
before_cache:
25+
26+
# Ubuntu Linux with glibc using g++-5
27+
- stage: Linter + Doxygen + non-debug Ubuntu/gcc-5 test
28+
os: linux
29+
sudo: false
30+
compiler: gcc
31+
cache: ccache
32+
addons:
33+
apt:
34+
sources:
35+
- ubuntu-toolchain-r-test
36+
packages:
37+
- libwww-perl
38+
- g++-5
39+
- libubsan0
40+
before_install:
41+
- mkdir bin ; ln -s /usr/bin/gcc-5 bin/gcc
42+
# env: COMPILER=g++-5 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer"
43+
env: COMPILER="ccache g++-5"
44+
45+
# LOCAL CHANGES: Upgraded to diffblue-builder:alpine-0.0.4 because it includes Python
846

947
# Alpine Linux with musl-libc using g++
10-
- os: linux
48+
- stage: Test different OS/CXX/Flags
49+
os: linux
1150
sudo: required
1251
compiler: gcc
1352
cache: ccache
1453
services:
1554
- docker
1655
before_install:
17-
- docker pull diffblue/cbmc-builder:alpine-0.0.1
56+
- docker pull diffblue/diffblue-builder:alpine-0.0.4
1857
env:
19-
- PRE_COMMAND="docker run --env CBMC_ALPINE_BUILD=yes -v ${TRAVIS_BUILD_DIR}:/cbmc -v ${HOME}/.ccache:/root/.ccache diffblue/cbmc-builder:alpine-0.0.1"
58+
- PRE_COMMAND="docker run -v ${TRAVIS_BUILD_DIR}:/cbmc -v ${HOME}/.ccache:/root/.ccache diffblue/diffblue-builder:alpine-0.0.4"
2059
- COMPILER="ccache g++"
2160

2261
# LOCAL CHANGES: Added 'ant' to the OSX package list (needed by security-scanner regression tests)
2362

2463
# OS X using g++
25-
- os: osx
64+
- stage: Test different OS/CXX/Flags
65+
os: osx
2666
sudo: false
2767
compiler: gcc
2868
cache: ccache
@@ -31,42 +71,24 @@ matrix:
3171
- mkdir bin ; ln -s /usr/bin/gcc bin/gcc
3272
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache ant
3373
- export PATH=/usr/local/opt/ccache/libexec:$PATH
34-
- ccache -M 1G
35-
env: COMPILER=g++
74+
env: COMPILER="ccache g++"
3675

3776
# OS X using clang++
38-
- os: osx
77+
- stage: Test different OS/CXX/Flags
78+
os: osx
3979
sudo: false
4080
compiler: clang
4181
cache: ccache
4282
before_install:
4383
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache ant
4484
- export PATH=/usr/local/opt/ccache/libexec:$PATH
45-
- ccache -M 1G
4685
env:
4786
- COMPILER="ccache clang++ -Qunused-arguments -fcolor-diagnostics"
4887
- CCACHE_CPP2=yes
4988

50-
# Ubuntu Linux with glibc using g++-5
51-
- os: linux
52-
sudo: false
53-
compiler: gcc
54-
cache: ccache
55-
addons:
56-
apt:
57-
sources:
58-
- ubuntu-toolchain-r-test
59-
packages:
60-
- libwww-perl
61-
- g++-5
62-
- libubsan0
63-
before_install:
64-
- mkdir bin ; ln -s /usr/bin/gcc-5 bin/gcc
65-
# env: COMPILER=g++-5 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer"
66-
env: COMPILER="g++-5"
67-
6889
# Ubuntu Linux with glibc using g++-5, debug mode
69-
- os: linux
90+
- stage: Test different OS/CXX/Flags
91+
os: linux
7092
sudo: false
7193
compiler: gcc
7294
cache: ccache
@@ -82,12 +104,13 @@ matrix:
82104
- mkdir bin ; ln -s /usr/bin/gcc-5 bin/gcc
83105
# env: COMPILER=g++-5 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer"
84106
env:
85-
- COMPILER="g++-5"
107+
- COMPILER="ccache g++-5"
86108
- EXTRA_CXXFLAGS="-DDEBUG"
87109
script: echo "Not running any tests for a debug build."
88110

89111
# Ubuntu Linux with glibc using clang++-3.7
90-
- os: linux
112+
- stage: Test different OS/CXX/Flags
113+
os: linux
91114
sudo: false
92115
compiler: clang
93116
cache: ccache
@@ -110,7 +133,8 @@ matrix:
110133
- CCACHE_CPP2=yes
111134

112135
# Ubuntu Linux with glibc using clang++-3.7, debug mode
113-
- os: linux
136+
- stage: Test different OS/CXX/Flags
137+
os: linux
114138
sudo: false
115139
compiler: clang
116140
cache: ccache
@@ -134,42 +158,27 @@ matrix:
134158
- EXTRA_CXXFLAGS="-DDEBUG"
135159
script: echo "Not running any tests for a debug build."
136160

137-
# LOCAL CHANGES: added cbmc/ prefix to both these scripts (and the allow_failures entry for cpp-lint)
138-
139-
- env: NAME="CPP-LINT"
140-
install:
141-
script: cbmc/scripts/travis_lint.sh
142-
before_cache:
143-
144-
- env: NAME="DOXYGEN-CHECK"
145-
addons:
146-
apt:
147-
packages:
148-
- doxygen
149-
install:
150-
script: cbmc/scripts/travis_doxygen.sh
151-
before_cache:
152-
153161
allow_failures:
154-
- env: NAME="CPP-LINT"
155-
install:
156-
script: cbmc/scripts/travis_lint.sh
157-
before_cache:
162+
- <<: *linter-stage
163+
- <<: *doxygen-stage
158164

159165
# LOCAL CHANGES: added cbmc/ prefix to some of the following commands
160166
# LOCAL CHANGES: added goto-analyzer.dir, goto-diff.dir and goto-cc.dir to the additional build list (needed for CBMC's regression tests, but not by the security-scanner product)
161167

162168
install:
169+
- ccache --max-size=1G
163170
- COMMAND="make -C cbmc/src minisat2-download" &&
164171
eval ${PRE_COMMAND} ${COMMAND}
165172
- COMMAND="make -C cbmc/src boost-download" &&
166173
eval ${PRE_COMMAND} ${COMMAND}
174+
- COMMAND="make -C cbmc/src/ansi-c library_check" &&
175+
eval ${PRE_COMMAND} ${COMMAND}
167176
- COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"-Wall -Werror -pedantic -O2 -g -DUSE_BOOST $EXTRA_CXXFLAGS\" -j2" &&
168177
eval ${PRE_COMMAND} ${COMMAND}
169178
- COMMAND="make -C cbmc/src CXX=\"$COMPILER\" CXXFLAGS=\"$FLAGS $EXTRA_CXXFLAGS\" -j2 goto-analyzer.dir goto-cc.dir goto-diff.dir clobber.dir memory-models.dir musketeer.dir" &&
170179
eval ${PRE_COMMAND} ${COMMAND}
171180

172-
# LOCAL CHANGES: added cbmc/ prefix to CBMC's test commands and appended security-scanner test commands
181+
# LOCAL CHANGES: Added cbmc/ prefix, and added unit and regression tests to the end of the list.
173182

174183
script:
175184
- if [ -e bin/gcc ] ; then export PATH=$PWD/bin:$PATH ; fi ;

benchmarks/TRAINING/diffblue/taint_traces_05/AssignmentAction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import java.util.HashMap;
21
import java.util.List;
32
import java.io.InputStream;
43
import java.io.IOException;
@@ -10,16 +9,16 @@ public void doUpload_all(RunData data) {
109
FileItem fileFromUpload = null;
1110
fileFromUpload = params.getFileItem("file");
1211
InputStream fileContentStream = fileFromUpload.getInputStream();
13-
HashMap submissionTable = new HashMap();
12+
StringMap submissionTable = new StringMap();
1413
List submissions = null;
1514
submissions = AssignmentService.getSubmissions("some_param");
1615
submissionTable = uploadAll_parseZipFile(fileContentStream,submissionTable);
1716
uploadAll_updateSubmissions(submissionTable,submissions);
1817
}
1918

20-
private HashMap uploadAll_parseZipFile(
19+
private StringMap uploadAll_parseZipFile(
2120
InputStream fileContentStream,
22-
HashMap submissionTable
21+
StringMap submissionTable
2322
) {
2423
// If we do not load the class java.util.zip.ZipInputStream, then we
2524
// loose the class hierarchy => our rules stop working correctly. The
@@ -30,16 +29,16 @@ private HashMap uploadAll_parseZipFile(
3029
submissionTable.put("some_key",comment);
3130
return submissionTable;
3231
}
33-
32+
3433
private void uploadAll_updateSubmissions(
35-
HashMap submissionTable,
34+
StringMap submissionTable,
3635
List submissions
3736
) {
3837
if (submissions == null)
3938
return;
4039
AssignmentSubmissionEdit sEdit = editSubmission();
4140
if (sEdit != null)
42-
sEdit.setSubmittedText((String)submissionTable.get("some_key"));
41+
sEdit.setSubmittedText(submissionTable.get("some_key"));
4342
}
4443

4544
private AssignmentSubmissionEdit editSubmission() {
@@ -63,4 +62,3 @@ private String readIntoString(InputStream zin) {
6362
return buffer.toString();
6463
}
6564
}
66-
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
// This is a dumb map-like container to replace HashMap, because when HashMap's
3+
// method bodies are unavailable cbmc will assume that generic Object-returning
4+
// methods actually return an Object, not a subclass, and hence using it to store
5+
// Strings fails when downcasting the result of HashMap.get(...)
6+
7+
// This isn't actually a functional map, but is complex enough to exercise taint analysis.
8+
9+
public class StringMap {
10+
11+
private String[] store;
12+
13+
public StringMap() {
14+
store = new String[1];
15+
}
16+
17+
public void put(Object key, String value) {
18+
store[0] = value;
19+
}
20+
21+
public String get(Object key) {
22+
return store[0];
23+
}
24+
25+
}

benchmarks/TRAINING/diffblue/taint_traces_05_rules.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,27 @@
9898
}
9999
},
100100
{
101-
"comment": "Inserting a potentially tainted string into a HashMap container. Making the container tainted.",
102-
"id": "HashMap.put(*,String)->*",
103-
"class": "java.util.HashMap",
104-
"method": "put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
101+
"comment": "Inserting a potentially tainted string into a StringMap container. Making the container tainted.",
102+
"id": "StringMap.put(*,String)->*",
103+
"class": "StringMap",
104+
"method": "put:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;",
105105
"input": {
106106
"location": "arg2",
107107
"taint": "<toString(TaintedInputStream.read@byte[])@String>"
108108
},
109109
"result": {
110110
"location": "arg0",
111-
"taint": "<HashMap.put(toString(TaintedInputStream.read@byte[]))@HashMap>"
111+
"taint": "<StringMap.put(toString(TaintedInputStream.read@byte[]))@StringMap>"
112112
}
113113
},
114114
{
115-
"comment": "Retrieving a potentially tainted string from a HashMap container.",
116-
"id": "HashMap.get(HashMap,*)->String",
117-
"class": "java.util.HashMap",
118-
"method": "get:(Ljava/lang/Object;)Ljava/lang/Object;",
115+
"comment": "Retrieving a potentially tainted string from a StringMap container.",
116+
"id": "StringMap.get(StringMap,*)->String",
117+
"class": "StringMap",
118+
"method": "get:(Ljava/lang/Object;)Ljava/lang/String;",
119119
"input": {
120120
"location": "arg0",
121-
"taint": "<HashMap.put(toString(TaintedInputStream.read@byte[]))@HashMap>"
121+
"taint": "<StringMap.put(toString(TaintedInputStream.read@byte[]))@StringMap>"
122122
},
123123
"result": {
124124
"location": "return_value",

benchmarks/evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def __evaluate_benchmark(record):
143143
"--name \"" + record["name"] + "\" " +
144144
record["custom-options-for-security-scanner"]
145145
)
146+
print(command)
146147
os.system(command)
147148

148149
# And finally, we check whether the computed results match the expected ones.
File renamed without changes.

0 commit comments

Comments
 (0)