Skip to content

Commit

Permalink
check for sScanf error
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera committed Feb 16, 2024
1 parent 0d2674e commit 601cedf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions peers/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ func (h *Handshake) ReadFrom(r io.Reader) (n int64, err error) {

scanner.Scan()
_, err = fmt.Sscanf(scanner.Text(), "%s %s", &h.ProtocolIdentifier, &h.Version)
if err != nil {
return -1, err
}

scanner.Scan()
h.RemotePeer = scanner.Text()

scanner.Scan()
_, err = fmt.Sscanf(scanner.Text(), "%s %d %d", &h.LocalPeerIdentifier, &h.ProcessID, &h.RelativeProcessID)
if err != nil {
return -1, err
}

//TODO: find out how many bytes where read.
return -1, scanner.Err()
Expand Down

0 comments on commit 601cedf

Please sign in to comment.