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

Fix example in README #48

Closed
treiher opened this issue Apr 20, 2024 · 1 comment · Fixed by #50
Closed

Fix example in README #48

treiher opened this issue Apr 20, 2024 · 1 comment · Fixed by #50

Comments

@treiher
Copy link

treiher commented Apr 20, 2024

The example in the README leads to an exception:

  File "/tmp/.venv/lib/python3.11/site-packages/cobrafuzz/fuzzer.py", line 187, in _worker_run                                                                
    target(bytes(data))                                                                                                                                                     
  File "/tmp/test.py", line 10, in fuzz                                                                                                                       
    parser = HTMLParser()                                                                                                                                                   
             ^^^^^^^^^^                                                                                                                                                     
NameError: name 'HTMLParser' is not defined

Here is a fixed version:

from cobrafuzz.main import CobraFuzz


@CobraFuzz
def fuzz(buf: bytes) -> None:
    from html.parser import HTMLParser

    try:
        string = buf.decode("ascii")
        parser = HTMLParser()
        parser.feed(string)
    except UnicodeDecodeError:
        pass


if __name__ == "__main__":
    fuzz()

Apart from moving the import inside the function, I have also added type hints. That makes it more obvious what the type of buf is.

@senier senier mentioned this issue May 13, 2024
@senier
Copy link
Owner

senier commented May 13, 2024

Thanks @treiher for the report and the fix! Sorry for the delayed response - for some reason I received no notification for this issue.

The example in the README actually used to be the same as examples/fuzz_htmlparser/fuzz.py, but I forgot to update it when changing the fuzzer. I fixed it and implemented a check in #50 to ensure the code example in the README remains in sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants