qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] system/rtc: Silent overflow in qemu_timedate_diff()
@ 2025-08-11 10:08 Philippe Mathieu-Daudé
  2025-09-01 11:43 ` Philippe Mathieu-Daudé
  2025-09-01 12:08 ` Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-08-11 10:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Peter Maydell, Philippe Mathieu-Daudé

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é <philmd@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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-01 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 10:08 [PATCH] system/rtc: Silent overflow in qemu_timedate_diff() Philippe Mathieu-Daudé
2025-09-01 11:43 ` Philippe Mathieu-Daudé
2025-09-01 12:08 ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).