From 66db9b9ad83cbcb4421190281cda5afd10c0fa66 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Mon, 1 Jul 2024 09:57:29 +0800 Subject: [PATCH] return error in case there is not enough data available --- modules/l4ssh/matcher.go | 6 +++--- modules/l4xmpp/matcher.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/l4ssh/matcher.go b/modules/l4ssh/matcher.go index 3fb5e17..451bfec 100644 --- a/modules/l4ssh/matcher.go +++ b/modules/l4ssh/matcher.go @@ -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 } diff --git a/modules/l4xmpp/matcher.go b/modules/l4xmpp/matcher.go index e930f24..ec14ab3 100644 --- a/modules/l4xmpp/matcher.go +++ b/modules/l4xmpp/matcher.go @@ -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 }