1# Run a fuzz test to verify robustness against corrupted/malicious data. 2 3Import("env", "malloc_env") 4 5def 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) 11 12# We want both pointer and static versions of the AllTypes message 13# Prefix them with package name. 14env.Command("alltypes_static.proto", "#alltypes/alltypes.proto", 15 lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_static')) 16env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto", 17 lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_pointer')) 18 19p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"]) 20p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"]) 21fuzz = 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"]) 28 29env.RunTest(fuzz) 30 31fuzzstub = 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"]) 38 39generate_message = malloc_env.Program(["generate_message.c", 40 "alltypes_static.pb.c", 41 "$COMMON/pb_encode.o", 42 "$COMMON/pb_common.o"]) 43 44