From bb0e561caffba4592f908b44c8e327a2a60db629 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Fri, 16 May 2025 15:34:54 +0330 Subject: [PATCH] Sniffer: Fix potential infinite loop (#4726) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 风扇滑翔翼 --- app/dispatcher/default.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index c24e0bbc..544a0956 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -371,7 +371,10 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw return nil, ctx.Err() default: cachingStartingTimeStamp := time.Now() - cacheErr := cReader.Cache(payload, cacheDeadline) + err := cReader.Cache(payload, cacheDeadline) + if err != nil { + return nil, err + } cachingTimeElapsed := time.Since(cachingStartingTimeStamp) cacheDeadline -= cachingTimeElapsed @@ -381,12 +384,12 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw case common.ErrNoClue: // No Clue: protocol not matches, and sniffer cannot determine whether there will be a match or not totalAttempt++ case protocol.ErrProtoNeedMoreData: // Protocol Need More Data: protocol matches, but need more data to complete sniffing - if cacheErr != nil { // Cache error (e.g. timeout) counts for failed attempt - totalAttempt++ - } + // in this case, do not add totalAttempt(allow to read until timeout) default: return result, err } + } else { + totalAttempt++ } if totalAttempt >= 2 || cacheDeadline <= 0 { return nil, errSniffingTimeout