From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/3] tcp: Avoid false (but convoluted) positive Coverity CWE-476 warning
Date: Mon, 27 Feb 2023 21:50:25 +1100 [thread overview]
Message-ID: <Y/yK8UjSZScy3GfR@yekko> (raw)
In-Reply-To: <20230227095941.225672-3-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]
On Mon, Feb 27, 2023 at 10:59:40AM +0100, Stefano Brivio wrote:
> 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 <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> 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) {
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-02-27 13:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-27 9:59 [PATCH 0/3] Avoid some warnings reported by Coverity Stefano Brivio
2023-02-27 9:59 ` [PATCH 1/3] tcp, tcp_splice: Get rid of false positive CWE-394 Coverity warning from fls() Stefano Brivio
2023-02-27 10:49 ` David Gibson
2023-02-27 9:59 ` [PATCH 2/3] tcp: Avoid false (but convoluted) positive Coverity CWE-476 warning Stefano Brivio
2023-02-27 10:50 ` David Gibson [this message]
2023-02-27 9:59 ` [PATCH 3/3] tcp: Avoid (theoretical) resource leak (CWE-772) Coverity warning Stefano Brivio
2023-02-27 10:51 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/yK8UjSZScy3GfR@yekko \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).