From: Victor Julien Date: Tue, 26 Apr 2022 19:47:37 +0000 (+0200) Subject: detect/pcre: assist code analyzer around pointer logic X-Git-Tag: suricata-5.0.10~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13d0317e80a744199b5374d4a263ce37153ac7d3;p=thirdparty%2Fsuricata.git detect/pcre: assist code analyzer around pointer logic cppcheck: src/detect-pcre.c:381:27: warning: Either the condition 'pcap' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck] cut_capture = MIN((pcap - regexstr), (fcap - regexstr)); ^ src/detect-pcre.c:378:18: note: Assuming that condition 'pcap' is not redundant else if (pcap && !fcap) ^ src/detect-pcre.c:381:27: note: Null pointer subtraction cut_capture = MIN((pcap - regexstr), (fcap - regexstr)); ^ Bug: #5291. (cherry picked from commit 69b8b48b9422279943c083a24e5baf64e1c4aa94) --- diff --git a/src/detect-pcre.c b/src/detect-pcre.c index f0a7798c9d..8bbdf56ea8 100644 --- a/src/detect-pcre.c +++ b/src/detect-pcre.c @@ -353,8 +353,11 @@ static DetectPcreData *DetectPcreParse (DetectEngineCtx *de_ctx, cut_capture = fcap - regexstr; else if (pcap && !fcap) cut_capture = pcap - regexstr; - else + else { + BUG_ON(pcap == NULL); // added to assist cppcheck + BUG_ON(fcap == NULL); cut_capture = MIN((pcap - regexstr), (fcap - regexstr)); + } SCLogDebug("cut_capture %d", cut_capture);