From 0d278aa089bf3a00bf2d6e56d2f01ea4677190a7 Mon Sep 17 00:00:00 2001 From: Shaleen Bathla Date: Wed, 28 Dec 2022 20:17:12 +0530 Subject: [PATCH] nwfilter: use time_t for timeout for consistency 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 Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/nwfilter/nwfilter_dhcpsnoop.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index a10a14cfc1..e604d67b96 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; + 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 "