Skip to content

Commit

Permalink
Merge pull request #7 from bersoare/bounds_check
Browse files Browse the repository at this point in the history
check buffer length before accessing it
  • Loading branch information
j-keck authored Jun 1, 2021
2 parents ece45f6 + ab5f188 commit 6866322
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arping_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func (s *BsdSocket) receive() (arpDatagram, time.Time, error) {
// skip bpf header + 14 bytes ethernet header
var hdrLength = bpfHdrLength + 14

if n <= hdrLength || len(buffer) <= hdrLength {
// amount of bytes read by socket is less than an ethernet header. clearly not what we look for
return arpDatagram{}, time.Now(), fmt.Errorf("buffer with invalid length")

}
return parseArpDatagram(buffer[hdrLength:n]), time.Now(), nil
}

Expand Down
6 changes: 6 additions & 0 deletions arping_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arping

import (
"fmt"
"net"
"syscall"
"time"
Expand Down Expand Up @@ -34,6 +35,11 @@ func (s *LinuxSocket) receive() (arpDatagram, time.Time, error) {
if err != nil {
return arpDatagram{}, time.Now(), err
}
if n <= 14 {
// amount of bytes read by socket is less than an ethernet header. clearly not what we look for
return arpDatagram{}, time.Now(), fmt.Errorf("buffer with invalid length")

}
// skip 14 bytes ethernet header
return parseArpDatagram(buffer[14:n]), time.Now(), nil
}
Expand Down

0 comments on commit 6866322

Please sign in to comment.