Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing urllib3 port binding crash #9958

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions projects/urllib3/fuzz_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

import atheris
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
import random
import sys
import threading
import time

with atheris.instrument_imports():
import urllib3
import urllib3

timeout = urllib3.util.Timeout(connect=1.0, read=1.0)
urllib_pool = urllib3.PoolManager(timeout=timeout)
Expand Down Expand Up @@ -117,13 +117,22 @@ def TestOneInput(input_bytes):
r.data
r.headers


if __name__ == "__main__":
x = threading.Thread(target=run_webserver, daemon=True)
x.start()
def main():
# Try and get an open port to run our test web server
for attempt in range(10):
try:
PORT = random.randint(8000,9999)
x = threading.Thread(target=run_webserver, daemon=True)
x.start()
break
except OSError as e:
pass

time.sleep(0.5) # Short delay to start test server

atheris.Setup(sys.argv, TestOneInput)

atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()

if __name__ == "__main__":
main()