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

Minor nitpick in the Fuzzer class defenition #106

Conversation

hexagonrecursion
Copy link

The current code says:

# Note: the list comprehension below does not invoke self.run() for subclasses
# return [self.run(runner) for i in range(trials)]

The code uses this as a justification to use a loop instead of a list comprehension. This is incorrect: self.run() inside a list comprehension calls the correct subclass method just fine. Proof: https://mybinder.org/v2/gh/hexagonrecursion/fuzzingbook.git/proof?filepath=docs%2Fnotebooks%2FFuzzer-proof.ipynb

class Fuzzer(object):
    def __init__(self):
        pass

    def fuzz(self):
        """Return fuzz input"""
        return ""

    def run(self, runner=Runner()):
        """Run `runner` with fuzz input"""
        return runner.run(self.fuzz())

    def runs(self, runner=PrintRunner(), trials=10):
        """Run `runner` with fuzz input, `trials` times"""
        return [self.run(runner) for i in range(trials)]
    
        
class Foo(Fuzzer):
    def run(self, runner=Runner()):
        print('Foo.run')
        
Foo().runs()
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run

[None, None, None, None, None, None, None, None, None, None]

The current code says:
```py
# Note: the list comprehension below does not invoke self.run() for subclasses
# return [self.run(runner) for i in range(trials)]
```
The code uses this as a justification to use a loop instead of a list comprehension. This is incorrect: self.run() inside a list comprehension calls the correct subclass method just fine. Proof: https://mybinder.org/v2/gh/hexagonrecursion/fuzzingbook.git/proof?filepath=docs%2Fnotebooks%2FFuzzer-proof.ipynb
```py
class Fuzzer(object):
    def __init__(self):
        pass

    def fuzz(self):
        """Return fuzz input"""
        return ""

    def run(self, runner=Runner()):
        """Run `runner` with fuzz input"""
        return runner.run(self.fuzz())

    def runs(self, runner=PrintRunner(), trials=10):
        """Run `runner` with fuzz input, `trials` times"""
        return [self.run(runner) for i in range(trials)]
    
        
class Foo(Fuzzer):
    def run(self, runner=Runner()):
        print('Foo.run')
        
Foo().runs()
```
```
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run
Foo.run

[None, None, None, None, None, None, None, None, None, None]
```
@vrthra
Copy link
Member

vrthra commented Sep 12, 2021

Hi @hexagonrecursion, can you explain the actual change? Is this simply to remove the note? The github diff doesn't know about Jupyter notebooks, and the diff it shows is incomprehensible.

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 this pull request may close these issues.

None yet

2 participants