From nobody Wed May 15 20:06:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661271772; cv=none; d=zohomail.com; s=zohoarc; b=dHmxCQV7jlZ+Ji6Miq80iYWGGnWt9hcDY8S5V7Z1aYSGH6L8gDnJHVSV199Moe/YGqhVHNJ4dwCnUKT2ATYI++f/Jm7gzPUq+AdnxI/Kmd9x1OFWnmvaRwFlJRtKb1Ed2AKdo+3ofcRwBBUpHgtyDy2v0+Kz2nOsNk4+8InSDmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661271772; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J03L2t2QPn7GsOVgEJTuXlcD/eAat0XXDuWCGynVoQA=; b=nlWWNXl4F8AQS0bIIaP3S7apz35Wq1JxjQDdDZQW8sSRc+w3Zhe8/QHo99myjOYtAA2ue1IqfZ3ELI4U2ZCcLYxF/CeXeUelM++VEZPcUBkQtDL0C4wdjMah4Jh14VFUf3oeiXfADZeJd6CBURvak2N0gGDZJpWQDsuBhj+H/hU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661271772397898.8822363176623; Tue, 23 Aug 2022 09:22:52 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-n9vGTceJN7ONgvf83zsC5A-1; Tue, 23 Aug 2022 12:22:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23074802529; Tue, 23 Aug 2022 16:22:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D41FB2026D4C; Tue, 23 Aug 2022 16:22:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C047D1946A47; Tue, 23 Aug 2022 16:22:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4BEF31946A40 for ; Tue, 23 Aug 2022 16:22:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 214904011A58; Tue, 23 Aug 2022 16:22:39 +0000 (UTC) Received: from nautilus.home.lan (unknown [10.40.192.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A1E840CF8E7; Tue, 23 Aug 2022 16:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661271770; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J03L2t2QPn7GsOVgEJTuXlcD/eAat0XXDuWCGynVoQA=; b=DrPFb6wdCaH9LbfwMCzHPb0ofBifbkm5CvRKrMYLVOdvbHaNhVpmfhNz1v2iIaR3tenRhZ HK3cLY6YnkSCjMi017LRy5ejlwjFNxOwL36gJqW2GHY+Xeb6zVhEJo8oxgDgGWXQ1pTMJf LKXNDH/zJIcnV2wHhE17E/bBD1jLS0A= X-MC-Unique: n9vGTceJN7ONgvf83zsC5A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] nwfilter: Replace a redundant 'now' variable with a direct time(0) call Date: Tue, 23 Aug 2022 18:22:36 +0200 Message-Id: <694947e87dc42cc084eb0f6426d716b5b2ed7837.1661271752.git.eskultet@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eskultet@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661271773079100005 Content-Type: text/plain; charset="utf-8"; x-default="true" In this very instance having a variable is pointless since there is only a single time(0) call in the whole function. Signed-off-by: Erik Skultety --- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index a10a14cfc1..18812c0b20 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -1723,13 +1723,11 @@ virNWFilterSnoopLeaseFileLoad(void) char ipstr[INET_ADDRSTRLEN], srvstr[INET_ADDRSTRLEN]; virNWFilterSnoopIPLease ipl; virNWFilterSnoopReq *req; - time_t now; FILE *fp; int ln =3D 0, tmp; VIR_LOCK_GUARD lock =3D virLockGuardLock(&virNWFilterSnoopState.snoopL= ock); =20 fp =3D fopen(LEASEFILE, "r"); - time(&now); while (fp && fgets(line, sizeof(line), fp)) { if (line[strlen(line)-1] !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1746,7 +1744,7 @@ virNWFilterSnoopLeaseFileLoad(void) "line %d corrupt"), ln); break; } - if (ipl.timeout && ipl.timeout < now) + if (ipl.timeout && ipl.timeout < time(0)) continue; req =3D virNWFilterSnoopReqGetByIFKey(ifkey); if (!req) { --=20 2.37.2 From nobody Wed May 15 20:06:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661271770; cv=none; d=zohomail.com; s=zohoarc; b=cJE4Jsa7ccw2w6OYQlikS2PC2k4w7wl77JXtqOr/Ne+zpGBaiCZPVFfz4dFhZXATVIuvi45xhWS3IbSxJDdOyX4DXxHXdhCr3ww4e+w1oEDOCP8J0IL8eSfB54pX5SBYHcLMXtpAMnAL5B81cbVn8D/4x+HZPWhl9MnjY+pbJTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661271770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xH7kd3g4gc1ggw6FfStrtxqW5G7NFArDFzhOOp33g+k=; b=i0TWD/XTZIGFDA2Q26600HF0MSuPwBotv7H3QGm+H4s6ky3mS3tAOWh7mSUnRUaUE21yFOR9wYWfyUEBlVfLhRJvvHn+NlljM4gTxcLfhv0Wp5b+LMFdrtFGe9QrvszoSlZUExqGT7hifek184ArOozK+kuqUcvuKiKBDaz4yE0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661271770417287.72789666376593; Tue, 23 Aug 2022 09:22:50 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-mfC9kt8qMCWQFbuoGgfxmQ-1; Tue, 23 Aug 2022 12:22:45 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A73281DA53; Tue, 23 Aug 2022 16:22:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 739F2492CA4; Tue, 23 Aug 2022 16:22:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1A86F1946A67; Tue, 23 Aug 2022 16:22:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0B4F21946A65 for ; Tue, 23 Aug 2022 16:22:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D8AA640CF8E7; Tue, 23 Aug 2022 16:22:39 +0000 (UTC) Received: from nautilus.home.lan (unknown [10.40.192.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CDA040CFD0D; Tue, 23 Aug 2022 16:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661271769; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xH7kd3g4gc1ggw6FfStrtxqW5G7NFArDFzhOOp33g+k=; b=RzJGZTgF7xY3lHb6Mm2elD+KNGklhcx8EzwQvbMKJo7C0n9q5jLRdhPE3RRjwvPE9vXWtX 2BnjE8+nMl9oMQGy6uCVH5tFoEZdqUlypo3tbFyVgLXLYTo6PIqySjtRjBN1VmMhrfR+Te gvep+otwOFnxCQVCknxbyML7pj7gcfA= X-MC-Unique: mfC9kt8qMCWQFbuoGgfxmQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] nwfilter: Fix timeout data type reported by coverity Date: Tue, 23 Aug 2022 18:22:37 +0200 Message-Id: <9645100acb80919520a0ec9603b377fcbce7d9cb.1661271752.git.eskultet@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eskultet@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661271771105100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Coverity reports: virNWFilterSnoopIPLeaseUpdate(virNWFilterSnoopIPLease *ipl, time_t timeout) { if (timeout < ipl->timeout) return; /* no take-backs */ virNWFilterSnoopIPLeaseTimerDel(ipl); >>> CID 396747: High impact quality (Y2K38_SAFETY) >>> A "time_t" value is stored in an integer with too few bits to accommodate it. The expression "timeout" is cast to "unsigned int". ipl->timeout =3D timeout; virNWFilterSnoopIPLeaseTimerAdd(ipl); } Given that it doesn't make sense for a timeout to be negative, let's store it as unsigned long long and typecast all affected time_t occurrences accordingly. Since the affected places only ever get the current time which is not going to be negative (unless it's year 2038 and a 32bit architecture) we can safely cast them. Signed-off-by: Erik Skultety Reviewed-by: Peter Krempa --- src/nwfilter/nwfilter_dhcpsnoop.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 18812c0b20..0977951be1 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -146,7 +146,7 @@ struct _virNWFilterSnoopIPLease { virSocketAddr ipAddress; virSocketAddr ipServer; virNWFilterSnoopReq * snoopReq; - unsigned int timeout; + unsigned long long timeout; /* timer list */ virNWFilterSnoopIPLease *prev; virNWFilterSnoopIPLease *next; @@ -415,7 +415,8 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLe= ase *ipl, * virNWFilterSnoopIPLeaseUpdate - update the timeout on an IP lease */ static void -virNWFilterSnoopIPLeaseUpdate(virNWFilterSnoopIPLease *ipl, time_t timeout) +virNWFilterSnoopIPLeaseUpdate(virNWFilterSnoopIPLease *ipl, + unsigned long long timeout) { if (timeout < ipl->timeout) return; /* no take-backs */ @@ -447,7 +448,7 @@ virNWFilterSnoopIPLeaseGetByIP(virNWFilterSnoopIPLease = *start, static unsigned int virNWFilterSnoopReqLeaseTimerRun(virNWFilterSnoopReq *req) { - time_t now =3D time(0); + unsigned long long now =3D time(0); bool is_last =3D false; =20 /* protect req->start */ @@ -1580,7 +1581,8 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *i= fkey, return -1; =20 /* time intf ip dhcpserver */ - lbuf =3D g_strdup_printf("%u %s %s %s\n", ipl->timeout, ifkey, ipstr, = dhcpstr); + lbuf =3D g_strdup_printf("%llu %s %s %s\n", + ipl->timeout, ifkey, ipstr, dhcpstr); len =3D strlen(lbuf); =20 if (safewrite(lfd, lbuf, len) !=3D len) { @@ -1737,7 +1739,7 @@ virNWFilterSnoopLeaseFileLoad(void) } ln++; /* key len 54 =3D "VMUUID"+'-'+"MAC" */ - if (sscanf(line, "%u %54s %15s %15s", &ipl.timeout, + if (sscanf(line, "%llu %54s %15s %15s", &ipl.timeout, ifkey, ipstr, srvstr) < 4) { virReportError(VIR_ERR_INTERNAL_ERROR, _("virNWFilterSnoopLeaseFileLoad lease file " --=20 2.37.2