Coverage for /pythoncovmergedfiles/medio/medio/src/fuzzing/projects/pycups/fuzzer/fuzz_auth_callback.py: 29%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
13import sys
14import atheris
15import cups
17# callback that returns fuzzed password strings
18class PasswordCallback:
19 def __init__(self, fdp):
20 self.fdp = fdp
21 self.call_count = 0
23 def __call__(self, prompt: str, conn, method: str, resource: str, context=None):
24 self.call_count += 1
25 #return the fuzzed UTF-8 password
26 length = self.fdp.ConsumeIntInRange(0, 64)
27 pw_bytes = self.fdp.ConsumeBytes(length)
28 try:
29 return pw_bytes.decode('utf-8', errors='ignore')
30 except Exception:
31 return ""
33def TestOneInput(data: bytes):
34 if len(data) < 4:
35 return
37 fdp = atheris.FuzzedDataProvider(data)
39 try:
40 #connection object
41 conn = cups.Connection()
43 # fuzzed prompt/method/resource strings
44 prompt = fdp.ConsumeUnicodeNoSurrogates(20)
45 method = fdp.ConsumeUnicodeNoSurrogates(20)
46 resource = fdp.ConsumeUnicodeNoSurrogates(20)
48 context_choice = fdp.ConsumeIntInRange(0, 1)
49 context = {} if context_choice else None
51 #assigning the fuzzed callback to simulate cups password callback
52 conn.cb_password_callback = PasswordCallback(fdp)
54 #simulate calling password_callback
55 try:
56 result = conn.password_callback(
57 newstyle=fdp.ConsumeBool(),
58 prompt=prompt,
59 method=method,
60 resource=resource,
61 user_data=context
62 )
63 except Exception:
64 pass
66 except Exception:
67 pass
69def main():
70 atheris.instrument_all()
71 atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
72 atheris.Fuzz()
74if __name__ == "__main__":
75 main()