Skip to content

Commit

Permalink
return error in case there is not enough data available
Browse files Browse the repository at this point in the history
  • Loading branch information
WeidiDeng committed Aug 12, 2024
1 parent 8a25df6 commit 66db9b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions modules/l4ssh/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (*MatchSSH) CaddyModule() caddy.ModuleInfo {
// Match returns true if the connection looks like SSH.
func (m *MatchSSH) Match(cx *layer4.Connection) (bool, error) {
p := make([]byte, len(sshPrefix))
n, err := io.ReadFull(cx, p)
if err != nil || n < len(sshPrefix) {
return false, nil
_, err := io.ReadFull(cx, p)
if err != nil {
return false, err
}
return bytes.Equal(p, sshPrefix), nil
}
Expand Down
6 changes: 3 additions & 3 deletions modules/l4xmpp/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (*MatchXMPP) CaddyModule() caddy.ModuleInfo {
// Match returns true if the connection looks like XMPP.
func (m *MatchXMPP) Match(cx *layer4.Connection) (bool, error) {
p := make([]byte, minXmppLength)
n, err := io.ReadFull(cx, p)
if err != nil || n < minXmppLength { // needs at least 50 (fix for adium/pidgin)
return false, nil
_, err := io.ReadFull(cx, p)
if err != nil { // needs at least 50 (fix for adium/pidgin)
return false, err
}
return strings.Contains(string(p), xmppWord), nil
}
Expand Down

0 comments on commit 66db9b9

Please sign in to comment.