File: test_fuzz_setup.py

package info (click to toggle)
gensio 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,364 kB
  • sloc: ansic: 90,328; python: 5,220; sh: 4,935; cpp: 3,258; makefile: 1,418
file content (44 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (4)
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
#
#  gensio - A library for abstracting stream I/O
#  Copyright (C) 2018  Corey Minyard <minyard@acm.org>
#
#  SPDX-License-Identifier: GPL-2.0-only
#

#
# This program creates some random data into a file and then runs a
# gensio connector and accepter over stdio.  The data written to the
# accepter gensio filter is saved in tracefile.
#
# This is for support of fuzz testing.  The random data can be used to
# create a completely reproducible testcase with the ssl library.  The
# tracefile is used for fuzzing the program.
#

import sys
import subprocess
import os

gensiot = sys.argv[1]
randfile = sys.argv[2]
filter1 = sys.argv[3]
filter2 = sys.argv[4]
tracefile = sys.argv[5]

p = subprocess.Popen(["dd", "if=/dev/urandom", "of=" + randfile, "count=256"],
                     stderr = subprocess.PIPE)
p.communicate()

cmd = (filter1 + ',trace(dir=write,raw,file=' + tracefile + '),stdio(noredir-stderr),' +
       gensiot + ' --dummyrand ' + randfile + ' -i echo -a "' + filter2 +
       ',stdio"')

p = subprocess.Popen([gensiot, '--dummyrand', randfile, '-i', 'stdio(self)', cmd],
                     stdin = subprocess.PIPE,
                     stdout = subprocess.PIPE,
                     stderr = None)

p.stdin.write("a".encode(encoding='utf8'))
p.stdin.close()
p.stdout.read(1)
p.wait()