qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: Lei He <helei.sig11@bytedance.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH] error-report: fix crash when compute iso8061 time
Date: Thu, 28 Apr 2022 12:58:46 +0400	[thread overview]
Message-ID: <CAMxuvawaXHkZMW=sLZwnbdTG2YZCN6ZGaFgFciyogFoqJdjcNQ@mail.gmail.com> (raw)
In-Reply-To: <20220428001450.13997-1-helei.sig11@bytedance.com>

Hi

On Thu, Apr 28, 2022 at 4:15 AM Lei He <helei.sig11@bytedance.com> wrote:
>
> g_get_real_time() returns the number of MICROSECONDS since
> January 1, 1970 UTC, but g_date_time_new_from_unix_utc() expects
> a timestamp in SECONDS.
>
> Directly call g_data_time_new_from_unix_utc(g_get_real_time()) causes
> overflow and a NULL pointer is returned, then qemu crashes.
>
> Use g_date_time_new_now_utc() instead, and add a check for NULL result.
>
> Signed-off-by: Lei He <helei.sig11@bytedance.com>

A fix is already in Paolo last pull request:
https://patchew.org/QEMU/20220428065335.189795-1-pbonzini@redhat.com/20220428065335.189795-2-pbonzini@redhat.com/

thanks

> ---
>  util/error-report.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/util/error-report.c b/util/error-report.c
> index dbadaf206d..d3c150661d 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -173,10 +173,13 @@ static char *
>  real_time_iso8601(void)
>  {
>  #if GLIB_CHECK_VERSION(2,62,0)
> -    g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc(g_get_real_time());
> +    g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
>      /* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */
>  #pragma GCC diagnostic push
>  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> +    if (!dt) {
> +        return NULL;
> +    }
>      return g_date_time_format_iso8601(dt);
>  #pragma GCC diagnostic pop
>  #else
> @@ -199,8 +202,10 @@ static void vreport(report_type type, const char *fmt, va_list ap)
>
>      if (message_with_timestamp && !monitor_cur()) {
>          timestr = real_time_iso8601();
> -        error_printf("%s ", timestr);
> -        g_free(timestr);
> +        if (timestr) {
> +            error_printf("%s ", timestr);
> +            g_free(timestr);
> +        }
>      }
>
>      /* Only prepend guest name if -msg guest-name and -name guest=... are set */
> --
> 2.11.0
>



  reply	other threads:[~2022-04-28  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28  0:14 [PATCH] error-report: fix crash when compute iso8061 time Lei He
2022-04-28  8:58 ` Marc-André Lureau [this message]
2022-04-28  9:09   ` [External] " 何磊

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMxuvawaXHkZMW=sLZwnbdTG2YZCN6ZGaFgFciyogFoqJdjcNQ@mail.gmail.com' \
    --to=marcandre.lureau@redhat.com \
    --cc=helei.sig11@bytedance.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).