-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
p2p: add peer to peer fuzzing support (#2426)
Adds support for peer to peer fuzzing by adding a fuzz reader writer which intercepts all the libp2p messages and reads/writes fuzzed data. category: feature ticket: #2375
- Loading branch information
Showing
6 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright © 2022-2023 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 | ||
|
||
package p2p | ||
|
||
import ( | ||
fuzz "github.com/google/gofuzz" | ||
"github.com/libp2p/go-msgio/pbio" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
var ( | ||
_ pbio.Reader = fuzzReaderWriter{} | ||
_ pbio.Writer = fuzzReaderWriter{} | ||
) | ||
|
||
// fuzzReaderWriter implements the pbio.Reader and pbio.Writer interfaces and provides functionality | ||
// for reading and writing messages with fuzzed data. | ||
type fuzzReaderWriter struct { | ||
w pbio.Writer | ||
} | ||
|
||
// ReadMsg fuzzes the received message, and stores the fuzzed data in the provided `msg` argument. | ||
func (fuzzReaderWriter) ReadMsg(msg proto.Message) error { | ||
fuzz.New().Fuzz(msg) | ||
|
||
return nil | ||
} | ||
|
||
// WriteMsg writes the fuzzed message using the associated writer. | ||
func (f fuzzReaderWriter) WriteMsg(msg proto.Message) error { | ||
cloneMsg := proto.Clone(msg) | ||
fuzz.New().Fuzz(cloneMsg) | ||
|
||
return f.w.WriteMsg(cloneMsg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters