From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id AA2875A026C; Mon, 27 Feb 2023 10:59:41 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 2/3] tcp: Avoid false (but convoluted) positive Coverity CWE-476 warning Date: Mon, 27 Feb 2023 10:59:40 +0100 Message-Id: <20230227095941.225672-3-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227095941.225672-1-sbrivio@redhat.com> References: <20230227095941.225672-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: B44NTEBBHQGL6UYUV3JHLVEFUMUHUTU5 X-Message-ID-Hash: B44NTEBBHQGL6UYUV3JHLVEFUMUHUTU5 X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If there are no TCP options in the header, tcp_tap_handler() will pass the corresponding pointer, fetched via packet_get(), as NULL to tcp_conn_from_sock_finish(), which in turn indirectly calls tcp_opt_get(). If there are no options, tcp_opt_get() will stop right away because the option length is indicated as zero. However, if the logic is complicated enough to follow for static checkers, adding an explicit check against NULL in tcp_opt_get() is probably a good idea. Signed-off-by: Stefano Brivio --- tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index 41210a3..561064e 100644 --- a/tcp.c +++ b/tcp.c @@ -1114,7 +1114,7 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find, { uint8_t type, optlen; - if (!len) + if (!opts || !len) return -1; for (; len >= 2; opts += optlen, len -= optlen) { -- 2.39.1