Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build artificial samples with scons instead of make #16

Merged
merged 6 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,5 @@ src/cwe_checker.plugin
test/artificial_samples/dockcross*

.#*

.sconsign.dblite
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
install:
- sudo apt-get update
- sudo apt-get install -y execstack
- pip3 install --user scons
- docker

before_script:
Expand Down
2 changes: 1 addition & 1 deletion .travis_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#!/bin/bash
cd test/artificial_samples/
./install_cross_compilers.sh
make
scons-3
cd ../..
docker build -t cwe-checker .
15 changes: 8 additions & 7 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
0.2-dev (2019-XX-XX)
=====

- Refactoring: Unification of cwe_checker function interface
- Refactoring: Created utils module for JSON functionality
- Added check for CWE 248: Uncaught Exception (PR #5)
- Added automated test suite (run with make test) (PR #7)
- Improved cross compiling for acceptance test cases by using dockcross (PR #8)
- Added BAP recipe for standard cwe_checker run (PR #9)
- Improved check for CWE-476 (NULL Pointer Dereference) using data flow analysis (PR #11)
- Refactoring: Unification of cwe_checker function interface
- Refactoring: Created utils module for JSON functionality
- Added check for CWE 248: Uncaught Exception (PR #5)
- Added automated test suite (run with make test) (PR #7)
- Improved cross compiling for acceptance test cases by using dockcross (PR #8)
- Added BAP recipe for standard cwe_checker run (PR #9)
- Improved check for CWE-476 (NULL Pointer Dereference) using data flow analysis (PR #11)
- Switched C build system from make to scons (PR #16)

0.1 (2018-10-08)
=====
Expand Down
72 changes: 72 additions & 0 deletions test/artificial_samples/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import shutil

supported_architectures = ['x64', 'x86', 'arm', 'mips', 'ppc']

c_compilers = {'x64': 'gcc',
'x86': './dockcross-linux-x86 gcc',
'arm': 'arm-linux-gnueabi-gcc',
'mips': 'mips-linux-gnu-gcc',
'ppc': 'powerpc-linux-gnu-gcc'}

cpp_compilers = {'x64': 'g++',
'x86': './dockcross-linux-x86 g++',
'arm': 'arm-linux-gnueabi-g++-5',
'mips': 'mips-linux-gnu-g++-5',
'ppc': 'powerpc-linux-gnu-g++-5'}

c_flags = {'x64': '-g -fno-stack-protector -std=c11',
'x86': '-g -m32 -fno-stack-protector -std=c11',
'arm': '-g -fno-stack-protector -std=c11',
'mips': '-g -fno-stack-protector -std=c11',
'ppc': '-g -fno-stack-protector -std=c11'}

cpp_flags = {'x64': '-g -fno-stack-protector',
'x86': '-g -m32 -fno-stack-protector',
'arm': '-g -fno-stack-protector',
'mips': '-g -fno-stack-protector',
'ppc': '-g -fno-stack-protector'}

def optimize(filename):
optimize_me = ['cwe_476.c']
if filename in optimize_me:
return ' -O3'
else:
return ' -O0'

def compile_only_on_x64(filename, arch):
only_x64 = ['cwe_782.c']
return filename in only_x64 and arch != 'x64'

def build_c(arch):
if shutil.which(c_compilers[arch]) is not None:
c_programs = Glob('*.c')
for p in c_programs:
if compile_only_on_x64(str(p), arch):
print('Skipping architecture %s for %s' % (arch, str(p)))
continue
env = Environment(CC = c_compilers[arch],
CCFLAGS = c_flags[arch] + optimize(str(p)))
env.Program('build/%s_%s.out' % (str(p).split('.')[0], arch), 'build/%s' % str(p))
# TODO: call execstack -s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test right now that depends on the call of execstack?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe none, I do not know why it was there in the first place.

else:
print('Compiler %s for architecture %s is not installed!' % (c_compilers[arch], arch))


def build_cpp(arch):
if shutil.which(cpp_compilers[arch]) is not None:
cpp_programs = Glob('*.cpp')
for p in cpp_programs:
env = Environment(CC = cpp_compilers[arch],
CCFLAGS = cpp_flags[arch] + optimize(str(p)))
env.Program('build/%s_%s.out' % (str(p).split('.')[0], arch), 'build/%s' % str(p))
# TODO: call execstack -s
else:
print('Compiler %s for architecture %s is not installed!' % (cpp_compilers[arch], arch))


VariantDir('build', '.', duplicate=0)
for arch in supported_architectures:
print('Building for architecture %s' % arch)
build_c(arch)
build_cpp(arch)
126 changes: 0 additions & 126 deletions test/artificial_samples/makefile

This file was deleted.