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

Return error if writer is nil #8

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Return error if writer is nil #8

merged 2 commits into from
Jan 25, 2024

Conversation

boecklim
Copy link
Collaborator

Panics can happen in the function WriteMessageWithEncodingN()

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc22067]

goroutine 109 [running]:
github.com/libsv/go-p2p/wire.WriteMessageWithEncodingN({0x0, 0x0}, {0x27dfbc8, 0xc0224da7b8}, 0x8a27b8?, 0xe8f3e1e3, 0xce3ad94?)
	/home/runner/go/pkg/mod/github.com/libsv/[email protected]/wire/message.go:369 +0x747
github.com/libsv/go-p2p/wire.WriteMessageN(...)
	/home/runner/go/pkg/mod/github.com/libsv/[email protected]/wire/message.go:292
github.com/libsv/go-p2p/wire.WriteMessage({0x0?, 0x0?}, {0x27dfbc8?, 0xc0224da7b8?}, 0x540be400?, 0x2?)
	/home/runner/go/pkg/mod/github.com/libsv/[email protected]/wire/message.go:301 +0x2e
github.com/libsv/go-p2p.(*Peer).writeRetry.func1()

The panic may happen if the buffer hw is nil

@boecklim boecklim requested a review from icellan January 22, 2024 12:33
@icellan
Copy link
Collaborator

icellan commented Jan 22, 2024

@boecklim I don't think this is the solution. This would also mask the error to calling client.

hw is created just a few lines above, so I don't see how it is possible that it is nil. I think it is much more likely that the io.writer w is nil, which would mean this function is being incorrectly called. What you could do is check at the beginning of the function whether w is nil and return an error.

wire/message.go Outdated Show resolved Hide resolved
@boecklim boecklim changed the title Only write buffer if it is not nil Return error if writer is nil Jan 22, 2024
@boecklim boecklim merged commit 2a9fc3f into master Jan 25, 2024
3 checks passed
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