Per ctime(3) man-page:

  A negative value for tm_isdst causes the mktime() function to
  attempt to divine whether summer time is in effect for the
  specified time.  The tm_isdst and tm_gmtoff members are forced
  to zero by timegm().

  The mktime() function returns the specified calendar time; if
  the calendar time cannot be represented, it returns -1;

Coverity reports (CID 1547724 Overflowed return value) the
qemu_timedate_diff() method doesn't handle this error path.

Since this method was added in commit f650305967f ("Unify RTCs
that use host time, fix M48t59 alarm") in 2008, and there is no
open issue related to it, keep ignoring this unlikely case, but
add an assertion to make Coverity happy.

Fixes: CID 1547724
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
 system/rtc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/system/rtc.c b/system/rtc.c
index 56951288c40..070b99fe6ad 100644
--- a/system/rtc.c
+++ b/system/rtc.c
@@ -98,6 +98,7 @@ time_t qemu_timedate_diff(struct tm *tm)
         struct tm tmp = *tm;
         tmp.tm_isdst = -1; /* use timezone to figure it out */
         seconds = mktime(&tmp);
+        assert(seconds >= 0);
         break;
     }
     default:
-- 
2.49.0


Reply via email to