From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: Re: [PATCH 3/7] tap: Check return value of accept4() before calling getsockopt() Date: Thu, 22 Sep 2022 16:30:22 +1000 Message-ID: In-Reply-To: <20220921205507.2742203-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3110118713409884067==" --===============3110118713409884067== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On Wed, Sep 21, 2022 at 10:55:03PM +0200, Stefano Brivio wrote: > Reported by Coverity (CWE-119): > > Negative value used as argument to a function expecting a > positive value (for example, size of buffer or allocation) > > and harmless, because getsockopt() would return -EBADF if the > socket is -1, so we wouldn't print anything. > > Check if accept4() returns a valid socket before calling getsockopt() > on it. > > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/tap.c b/tap.c > index 3231da7..4d7422f 100644 > --- a/tap.c > +++ b/tap.c > @@ -872,11 +872,13 @@ static void tap_sock_unix_new(struct ctx *c) > int discard = accept4(c->fd_tap_listen, NULL, NULL, > SOCK_NONBLOCK); > > + if (discard == -1) > + return; > + > if (!getsockopt(discard, SOL_SOCKET, SO_PEERCRED, &ucred, &len)) > info("discarding connection from PID %i", ucred.pid); > > - if (discard != -1) > - close(discard); > + close(discard); > > return; > } -- 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 --===============3110118713409884067== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSXpCQUVCQ0FBZEZpRUVvVUx4V3U0L1dz MGRCK1h0Z3lwWTRnRXdZU0lGQW1Nc0FQWUFDZ2tRZ3lwWTRnRXcKWVNMQmFnLy9ZZS9P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