* [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff()
@ 2018-02-01 11:59 Gonglei
2018-02-06 15:52 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Gonglei @ 2018-02-01 11:59 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, shenghualong, Gonglei
From: shenghualong <shenghualong@huawei.com>
When the Windows guest users set the time to year 2099,
the return value of qemu_timedate_diff() will overflow
with variable clock mode as below format:
<clock offset='variable' adjustment='-1201568405' basis='utc'>
Let's change the return value of qemu_timedate_diff() from
int to time_t to fix the possible overflow problem.
Signed-off-by: shenghualong <shenghualong@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
include/qemu-common.h | 2 +-
vl.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 05319b9..6fb80aa 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -33,7 +33,7 @@ int qemu_main(int argc, char **argv, char **envp);
#endif
void qemu_get_timedate(struct tm *tm, int offset);
-int qemu_timedate_diff(struct tm *tm);
+time_t qemu_timedate_diff(struct tm *tm);
#define qemu_isalnum(c) isalnum((unsigned char)(c))
#define qemu_isalpha(c) isalpha((unsigned char)(c))
diff --git a/vl.c b/vl.c
index e517a8d..9d225da 100644
--- a/vl.c
+++ b/vl.c
@@ -146,7 +146,7 @@ int nb_nics;
NICInfo nd_table[MAX_NICS];
int autostart;
static int rtc_utc = 1;
-static int rtc_date_offset = -1; /* -1 means no change */
+static time_t rtc_date_offset = -1; /* -1 means no change */
QEMUClockType rtc_clock;
int vga_interface_type = VGA_NONE;
static int full_screen = 0;
@@ -812,7 +812,7 @@ void qemu_get_timedate(struct tm *tm, int offset)
}
}
-int qemu_timedate_diff(struct tm *tm)
+time_t qemu_timedate_diff(struct tm *tm)
{
time_t seconds;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff()
2018-02-01 11:59 [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff() Gonglei
@ 2018-02-06 15:52 ` Paolo Bonzini
2018-02-07 11:15 ` Gonglei (Arei)
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2018-02-06 15:52 UTC (permalink / raw)
To: Gonglei, qemu-devel; +Cc: shenghualong
On 01/02/2018 12:59, Gonglei wrote:
> From: shenghualong <shenghualong@huawei.com>
>
> When the Windows guest users set the time to year 2099,
> the return value of qemu_timedate_diff() will overflow
> with variable clock mode as below format:
>
> <clock offset='variable' adjustment='-1201568405' basis='utc'>
>
> Let's change the return value of qemu_timedate_diff() from
> int to time_t to fix the possible overflow problem.
>
> Signed-off-by: shenghualong <shenghualong@huawei.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Thanks, this makes sense. However, looking at the users, you should
also change the type of:
- the diff variable in hw/timer/m48t59.c function set_alarm;
- the offset argument of the RTC_CHANGE QAPI event (to int64)
- the sec_offset and alm_sec fields of MenelausState in hw/timer/twl92230.c
- the offset argument of qemu_get_timedate.
Thanks,
Paolo
> ---
> include/qemu-common.h | 2 +-
> vl.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 05319b9..6fb80aa 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -33,7 +33,7 @@ int qemu_main(int argc, char **argv, char **envp);
> #endif
>
> void qemu_get_timedate(struct tm *tm, int offset);
> -int qemu_timedate_diff(struct tm *tm);
> +time_t qemu_timedate_diff(struct tm *tm);
>
> #define qemu_isalnum(c) isalnum((unsigned char)(c))
> #define qemu_isalpha(c) isalpha((unsigned char)(c))
> diff --git a/vl.c b/vl.c
> index e517a8d..9d225da 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -146,7 +146,7 @@ int nb_nics;
> NICInfo nd_table[MAX_NICS];
> int autostart;
> static int rtc_utc = 1;
> -static int rtc_date_offset = -1; /* -1 means no change */
> +static time_t rtc_date_offset = -1; /* -1 means no change */
> QEMUClockType rtc_clock;
> int vga_interface_type = VGA_NONE;
> static int full_screen = 0;
> @@ -812,7 +812,7 @@ void qemu_get_timedate(struct tm *tm, int offset)
> }
> }
>
> -int qemu_timedate_diff(struct tm *tm)
> +time_t qemu_timedate_diff(struct tm *tm)
> {
> time_t seconds;
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff()
2018-02-06 15:52 ` Paolo Bonzini
@ 2018-02-07 11:15 ` Gonglei (Arei)
0 siblings, 0 replies; 3+ messages in thread
From: Gonglei (Arei) @ 2018-02-07 11:15 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel@nongnu.org; +Cc: shenghualong
> -----Original Message-----
> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> Sent: Tuesday, February 06, 2018 11:52 PM
> To: Gonglei (Arei); qemu-devel@nongnu.org
> Cc: shenghualong
> Subject: Re: [PATCH] vl: fix possible int overflow for qemu_timedate_diff()
>
> On 01/02/2018 12:59, Gonglei wrote:
> > From: shenghualong <shenghualong@huawei.com>
> >
> > When the Windows guest users set the time to year 2099,
> > the return value of qemu_timedate_diff() will overflow
> > with variable clock mode as below format:
> >
> > <clock offset='variable' adjustment='-1201568405' basis='utc'>
> >
> > Let's change the return value of qemu_timedate_diff() from
> > int to time_t to fix the possible overflow problem.
> >
> > Signed-off-by: shenghualong <shenghualong@huawei.com>
> > Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>
> Thanks, this makes sense. However, looking at the users, you should
> also change the type of:
>
> - the diff variable in hw/timer/m48t59.c function set_alarm;
>
> - the offset argument of the RTC_CHANGE QAPI event (to int64)
>
> - the sec_offset and alm_sec fields of MenelausState in hw/timer/twl92230.c
>
> - the offset argument of qemu_get_timedate.
>
OK, will do.
Thanks,
-Gonglei
> Thanks,
>
> Paolo
>
> > ---
> > include/qemu-common.h | 2 +-
> > vl.c | 4 ++--
> > 2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/qemu-common.h b/include/qemu-common.h
> > index 05319b9..6fb80aa 100644
> > --- a/include/qemu-common.h
> > +++ b/include/qemu-common.h
> > @@ -33,7 +33,7 @@ int qemu_main(int argc, char **argv, char **envp);
> > #endif
> >
> > void qemu_get_timedate(struct tm *tm, int offset);
> > -int qemu_timedate_diff(struct tm *tm);
> > +time_t qemu_timedate_diff(struct tm *tm);
> >
> > #define qemu_isalnum(c) isalnum((unsigned char)(c))
> > #define qemu_isalpha(c) isalpha((unsigned char)(c))
> > diff --git a/vl.c b/vl.c
> > index e517a8d..9d225da 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -146,7 +146,7 @@ int nb_nics;
> > NICInfo nd_table[MAX_NICS];
> > int autostart;
> > static int rtc_utc = 1;
> > -static int rtc_date_offset = -1; /* -1 means no change */
> > +static time_t rtc_date_offset = -1; /* -1 means no change */
> > QEMUClockType rtc_clock;
> > int vga_interface_type = VGA_NONE;
> > static int full_screen = 0;
> > @@ -812,7 +812,7 @@ void qemu_get_timedate(struct tm *tm, int offset)
> > }
> > }
> >
> > -int qemu_timedate_diff(struct tm *tm)
> > +time_t qemu_timedate_diff(struct tm *tm)
> > {
> > time_t seconds;
> >
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-07 11:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-01 11:59 [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff() Gonglei
2018-02-06 15:52 ` Paolo Bonzini
2018-02-07 11:15 ` Gonglei (Arei)
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).