Skip to content

Minor nitpick in the Fuzzer class defenition#106

Closed
hexagonrecursion wants to merge 1 commit intouds-se:masterfrom
hexagonrecursion:hexagonrecursion-patch-1
Closed

Minor nitpick in the Fuzzer class defenition#106
hexagonrecursion wants to merge 1 commit intouds-se:masterfrom
hexagonrecursion:hexagonrecursion-patch-1

Conversation

@hexagonrecursion
Copy link
Copy Markdown

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
Copy Markdown
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.

2 participants