-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
strcpy.py
44 lines (31 loc) · 1.19 KB
/
strcpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
from ..func import Func, TestData
def rand_str(length, byte_list=None):
if byte_list is None:
return "".join(chr(random.randint(0, 255)) for _ in xrange(length))
return "".join(random.choice(byte_list) for _ in xrange(length))
class strcpy(Func):
non_null = [chr(i) for i in range(1, 256)]
def __init__(self):
super(strcpy, self).__init__() #pylint disable=useless-super-delegation
def get_name(self):
return "strcpy"
def num_args(self):
return 2
def args(self): #pylint disable=no-self-use
return ["dst", "src"]
def can_call_other_funcs(self):
return False
def gen_input_output_pair(self):
# TODO we don't check the return val, some cases I saw char * strcpy, some size_t strcpy
strlen = random.randint(1, 80)
buf = rand_str(strlen, byte_list=strcpy.non_null) + "\x00"
result_buf = rand_str(strlen+1)
test_input = [result_buf, buf]
test_output = [buf, buf]
max_steps = 20
return_val = None
test = TestData(test_input, test_output, return_val, max_steps)
return test
def pre_test(self, func, runner):
return True