1 # Run a fuzz test to verify robustness against corrupted/malicious data.
3 Import("env", "malloc_env")
5 def set_pkgname(src, dst, pkgname):
6 data = open(str(src)).read()
7 placeholder = '// package name placeholder'
8 assert placeholder in data
9 data = data.replace(placeholder, 'package %s;' % pkgname)
10 open(str(dst), 'w').write(data)
12 # We want both pointer and static versions of the AllTypes message
13 # Prefix them with package name.
14 env.Command("alltypes_static.proto", "#alltypes/alltypes.proto",
15 lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_static'))
16 env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto",
17 lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_pointer'))
19 p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"])
20 p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"])
21 fuzz = malloc_env.Program(["fuzztest.c",
22 "alltypes_pointer.pb.c",
23 "alltypes_static.pb.c",
24 "$COMMON/pb_encode_with_malloc.o",
25 "$COMMON/pb_decode_with_malloc.o",
26 "$COMMON/pb_common_with_malloc.o",
27 "$COMMON/malloc_wrappers.o"])
31 fuzzstub = malloc_env.Program(["fuzzstub.c",
32 "alltypes_pointer.pb.c",
33 "alltypes_static.pb.c",
34 "$COMMON/pb_encode_with_malloc.o",
35 "$COMMON/pb_decode_with_malloc.o",
36 "$COMMON/pb_common_with_malloc.o",
37 "$COMMON/malloc_wrappers.o"])
39 generate_message = malloc_env.Program(["generate_message.c",
40 "alltypes_static.pb.c",
41 "$COMMON/pb_encode.o",
42 "$COMMON/pb_common.o"])