]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nwfilter: use time_t for timeout for consistency
authorShaleen Bathla <shaleen.bathla@oracle.com>
Wed, 28 Dec 2022 14:47:12 +0000 (20:17 +0530)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 Jan 2023 11:51:09 +0000 (12:51 +0100)
Coverity scan reports:
"A time_t value is stored in an integer with too few bits to accommodate
it. The expression timeout is cast to unsigned int"

We are already casting and storing time_t timeout variable into unsigned int.
We can use time_t for timeout and cast it to unsigned long (should be big enough)
instead of unsigned int in sscanf, g_strdup_printf as required.

Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/nwfilter/nwfilter_dhcpsnoop.c

index a10a14cfc16dc70e3c156fe0875e5af19abe53ae..e604d67b9677caeaef94cdfdfef2d903d6664705 100644 (file)
@@ -146,7 +146,7 @@ struct _virNWFilterSnoopIPLease {
     virSocketAddr              ipAddress;
     virSocketAddr              ipServer;
     virNWFilterSnoopReq *    snoopReq;
-    unsigned int               timeout;
+    time_t                     timeout;
     /* timer list */
     virNWFilterSnoopIPLease *prev;
     virNWFilterSnoopIPLease *next;
@@ -1580,7 +1580,9 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey,
         return -1;
 
     /* time intf ip dhcpserver */
-    lbuf = g_strdup_printf("%u %s %s %s\n", ipl->timeout, ifkey, ipstr, dhcpstr);
+    lbuf = g_strdup_printf("%llu %s %s %s\n",
+                           (unsigned long long) ipl->timeout,
+                           ifkey, ipstr, dhcpstr);
     len = strlen(lbuf);
 
     if (safewrite(lfd, lbuf, len) != len) {
@@ -1739,7 +1741,8 @@ virNWFilterSnoopLeaseFileLoad(void)
         }
         ln++;
         /* key len 54 = "VMUUID"+'-'+"MAC" */
-        if (sscanf(line, "%u %54s %15s %15s", &ipl.timeout,
+        if (sscanf(line, "%llu %54s %15s %15s",
+                   (unsigned long long *) &ipl.timeout,
                    ifkey, ipstr, srvstr) < 4) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("virNWFilterSnoopLeaseFileLoad lease file "