瀏覽代碼

Sniffer: Fix potential infinite loop (#4726)

Co-authored-by: 风扇滑翔翼 <[email protected]>
patterniha 5 月之前
父節點
當前提交
bb0e561caf
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      app/dispatcher/default.go

+ 7 - 4
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