Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipr Toolchain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
Zipr Toolchain
Commits
38d4ba68
Commit
38d4ba68
authored
7 years ago
by
an7s
Browse files
Options
Downloads
Patches
Plain Diff
Test for functionality and detection
Former-commit-id: fc9925c890c60552ae4777c1d7b1a7313399d432
parent
470e8330
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitattributes
+2
-0
2 additions, 0 deletions
.gitattributes
tools/transforms/tests/test_buffer_overflow.c
+19
-0
19 additions, 0 deletions
tools/transforms/tests/test_buffer_overflow.c
tools/transforms/tests/test_buffer_overflow.sh
+114
-0
114 additions, 0 deletions
tools/transforms/tests/test_buffer_overflow.sh
with
135 additions
and
0 deletions
.gitattributes
+
2
−
0
View file @
38d4ba68
...
...
@@ -1253,6 +1253,8 @@ tools/transforms/globals.h -text
tools/transforms/integertransformdriver.cpp -text
tools/transforms/nulltransform.cpp -text
tools/transforms/sample_meds_int.annot -text
tools/transforms/tests/test_buffer_overflow.c -text
tools/transforms/tests/test_buffer_overflow.sh -text
tools/transforms/transformutils.cpp -text
tools/transforms/transformutils.h -text
xform/Makefile.in -text
...
...
This diff is collapsed.
Click to expand it.
tools/transforms/tests/test_buffer_overflow.c
0 → 100644
+
19
−
0
View file @
38d4ba68
#include
<stdio.h>
#include
<string.h>
#define BUFSIZE 32
void
do_overflow
(
char
*
s
)
{
char
tmp
[
BUFSIZE
];
strcpy
(
tmp
,
s
);
printf
(
"target string is: %s
\n
"
,
tmp
);
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
>
1
)
do_overflow
(
argv
[
1
]);
else
printf
(
"specify long string on command line as argument to overflow (bufsize=%d)
\n
"
,
BUFSIZE
);
}
This diff is collapsed.
Click to expand it.
tools/transforms/tests/test_buffer_overflow.sh
0 → 100755
+
114
−
0
View file @
38d4ba68
#!/bin/bash
do_p1
()
{
if
[[
-f
$2
]]
;
then
echo
"Eliding rebuild of
$2
"
else
if
[
-z
"
$3
"
]
;
then
$PSZ
$1
$2
--step
p1transform
=
on
else
$PSZ
$1
$2
--step
p1transform
=
on
--step-option
p1transform:
"
$3
"
fi
fi
}
get_correct
()
{
./test_buffer_overflow.exe
>
correct
./test_buffer_overflow.exe abc
>>
correct
}
test_functional
()
{
./
$1
>
out
./
$1
abc
>>
out
cmp out correct
if
[
$?
=
1
]
;
then
fails
=
$(
expr
$fails
+ 1
)
echo test
failed
$1
$2
$3
echo
"=== out ==="
cat
out
echo
"======"
else
passes
=
$(
expr
$passes
+ 1
)
echo test
passed.
fi
}
test_detection
()
{
./
$1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
exitcode
=
$?
if
[
$exitcode
-eq
$2
]
;
then
passes
=
$(
expr
$passes
+ 1
)
echo test
passed.
else
fails
=
$(
expr
$fails
+ 1
)
echo
"test failed: does not detect overflow or wrong exit code:
$1
(expected
$2
, got
$exitcode
)"
fi
}
build
()
{
gcc
-o
test_buffer_overflow.exe test_buffer_overflow.c
-fno-stack-protector
}
protect
()
{
do_p1 ./test_buffer_overflow.exe test_buffer_overflow.exe.p1.189
do_p1 ./test_buffer_overflow.exe test_buffer_overflow.exe.p1.188
"--detection_policy exit --detection_exit_code 188"
do_p1 ./test_buffer_overflow.exe test_buffer_overflow.exe.p1.hlt
"--detection_policy halt"
}
clean
()
{
rm
out 2>/dev/null
rm
correct 2>/dev/null
rm
-Rf
test_buffer_overflow.exe
*
peasoup_exe
*
2>/dev/null
}
report
()
{
total
=
$(
expr
$passes
+
$fails
)
echo
"Passes:
$passes
/
$total
"
echo
"Fails :
$fails
/
$total
"
}
main
()
{
clean
build
protect
get_correct
echo
"Test functionality"
test_functional test_buffer_overflow.exe
# unprotected - should pass!
test_functional test_buffer_overflow.exe.p1.189
test_functional test_buffer_overflow.exe.p1.188
test_functional test_buffer_overflow.exe.p1.hlt
report
echo
"Test detection"
passes
=
0
fails
=
0
test_detection test_buffer_overflow.exe.p1.189 189
test_detection test_buffer_overflow.exe.p1.188 188
test_detection test_buffer_overflow.exe.p1.hlt 139
report
if
[[
$1
==
"-k"
]]
;
then
echo
"Skipping cleanup"
else
clean
fi
}
passes
=
0
fails
=
0
main
$*
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment