Skip to content

Commit 2311e90

Browse files
authored
Merge pull request #2366 from marek-trtik/full_slicer/adapted_benchmarks_from_security_scanner
SEC-477: Added three regression tests for the full-slicer.
2 parents 0ee1fbb + 1977683 commit 2311e90

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// This is a benchmark for the full-slicer
2+
// This is a simplified version of end-to-end regression tests
3+
// 'general005', 'general006', and 'general007' of the security-scanner.
4+
5+
#include <assert.h>
6+
#include <stdbool.h>
7+
#include <stdlib.h>
8+
9+
struct object
10+
{
11+
bool Tainted_stream;
12+
};
13+
14+
struct java_array
15+
{
16+
struct object super;
17+
char *data;
18+
int length;
19+
};
20+
21+
struct java_array_wrapper
22+
{
23+
struct java_array super;
24+
bool Tainted_byte_array;
25+
};
26+
27+
struct InputStream
28+
{
29+
struct object super;
30+
struct java_array_wrapper *s;
31+
};
32+
33+
struct ServletInputStream
34+
{
35+
struct InputStream super;
36+
};
37+
38+
struct HttpServletRequest
39+
{
40+
struct ServletInputStream *s;
41+
};
42+
43+
void getBytes(struct java_array_wrapper *data, struct InputStream *in)
44+
{
45+
// These 2 lines are wrongly sliced away!
46+
if(in->super.Tainted_stream)
47+
data->Tainted_byte_array = true;
48+
}
49+
50+
struct InputStream *getInputStream(struct HttpServletRequest *this)
51+
{
52+
return &this->s->super;
53+
}
54+
55+
struct InputStream *getInStream(struct HttpServletRequest *request)
56+
{
57+
struct InputStream *x = getInputStream(request);
58+
x->super.Tainted_stream = true;
59+
return x;
60+
}
61+
62+
extern void *CProver_nondetWithNull();
63+
64+
int main()
65+
{
66+
struct HttpServletRequest *request = CProver_nondetWithNull();
67+
struct InputStream *in0 = getInStream(request);
68+
struct InputStream *in = in0;
69+
struct java_array_wrapper *data,
70+
*tmp1 =
71+
(struct java_array_wrapper *)malloc(sizeof(struct java_array_wrapper));
72+
tmp1->Tainted_byte_array = false;
73+
tmp1->super.super.Tainted_stream = false;
74+
data = tmp1;
75+
getBytes(data, in);
76+
if(data->Tainted_byte_array)
77+
assert(false);
78+
return 0;
79+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
main.c
3+
--full-slice --add-library
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
This is a simplified version of end-to-end regression tests 'general005', 'general006', and 'general007' of the security-scanner.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This is a benchmark for the full-slicer
2+
// It is a simplified version of end-to-end regression test
3+
// 'taint_crossing_substr_and_concatenation' of the security-scanner.
4+
5+
#include <assert.h>
6+
#include <stdbool.h>
7+
#include <stdlib.h>
8+
9+
extern int CProver_nondetInt();
10+
11+
struct object
12+
{
13+
bool X;
14+
bool SBX;
15+
};
16+
17+
struct String
18+
{
19+
struct object super;
20+
};
21+
22+
struct StringBuilder
23+
{
24+
struct object super;
25+
};
26+
27+
struct String *source()
28+
{
29+
return (struct String *)malloc(sizeof(struct String));
30+
}
31+
32+
struct StringBuilder *append(struct StringBuilder *sb, struct String *s)
33+
{
34+
return sb;
35+
}
36+
37+
struct String *toString(struct StringBuilder *sb)
38+
{
39+
return (struct String *)malloc(sizeof(struct String));
40+
}
41+
42+
int main()
43+
{
44+
struct StringBuilder *tmp1, *sb;
45+
struct String *tmp2, *tainted;
46+
47+
sb = (struct StringBuilder *)malloc(sizeof(struct StringBuilder));
48+
tainted = source();
49+
tainted->super.X = true;
50+
tmp1 = append(sb, tainted);
51+
52+
// Next 2 lines are wrongly sliced away!
53+
if(tainted->super.X)
54+
sb->super.SBX = true;
55+
56+
tmp2 = toString(tmp1);
57+
if(tmp1->super.SBX)
58+
tmp2->super.X = true;
59+
if(tmp2->super.X)
60+
assert(false);
61+
return 0;
62+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--full-slice --add-library
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
This is a simplified version of end-to-end regression test 'taint_crossing_substr_and_concatenation' of the security-scanner.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This is a benchmark for the full-slicer
2+
// This is a simplified version of end-to-end regression test
3+
// 'taint_over_list' of the security-scanner.
4+
5+
#include <assert.h>
6+
#include <stdbool.h>
7+
#include <stdlib.h>
8+
9+
extern void *CProver_nondetWithNull();
10+
11+
struct object
12+
{
13+
bool Tainted_data;
14+
};
15+
16+
struct java_array
17+
{
18+
struct object super;
19+
void **data;
20+
int length;
21+
};
22+
23+
struct ArrayList
24+
{
25+
struct java_array *data;
26+
int last;
27+
};
28+
29+
struct A
30+
{
31+
struct object super;
32+
};
33+
34+
void ArrayList_init(struct ArrayList *this)
35+
{
36+
this->data = CProver_nondetWithNull();
37+
this->last = 0;
38+
}
39+
40+
void ArrayList_add(struct ArrayList *this, struct object *o)
41+
{
42+
// Next 2 lines are wrongly sliced away!
43+
this->data->data[this->last] = o;
44+
this->last += 1;
45+
}
46+
47+
struct object *ArrayList_get(struct ArrayList *this, int idx)
48+
{
49+
return this->data->data[idx];
50+
}
51+
52+
int main()
53+
{
54+
struct ArrayList *L;
55+
struct A *tmp1;
56+
struct object *tmp2, *tmp3;
57+
L = CProver_nondetWithNull();
58+
ArrayList_init(L);
59+
tmp1 = (struct A *)malloc(sizeof(struct A));
60+
ArrayList_add(L, (struct object *)&tmp1->super);
61+
tmp2 = ArrayList_get(L, 0);
62+
63+
// The next line is wrongly sliced away!
64+
((struct A *)tmp2)->super.Tainted_data = true;
65+
66+
tmp3 = ArrayList_get(L, 0);
67+
if(((struct A *)tmp3)->super.Tainted_data)
68+
assert(false);
69+
return 0;
70+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--full-slice --add-library
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
This is a simplified version of end-to-end regression test 'taint_over_list' of the security-scanner.

0 commit comments

Comments
 (0)