From patchwork Thu Feb 1 11:59:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 10195431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C36F60380 for ; Thu, 1 Feb 2018 12:01:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9120289F1 for ; Thu, 1 Feb 2018 12:01:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB13C28797; Thu, 1 Feb 2018 12:01:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4276E28797 for ; Thu, 1 Feb 2018 12:01:12 +0000 (UTC) Received: from localhost ([::1]:59453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehDYF-0005Ix-1Q for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Feb 2018 07:01:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehDXK-0004rI-DZ for qemu-devel@nongnu.org; Thu, 01 Feb 2018 07:00:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehDXB-0004wm-72 for qemu-devel@nongnu.org; Thu, 01 Feb 2018 07:00:14 -0500 Received: from [45.249.212.32] (port=43922 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ehDXA-0004qY-RT for qemu-devel@nongnu.org; Thu, 01 Feb 2018 07:00:05 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 74FEA7169166E; Thu, 1 Feb 2018 19:59:46 +0800 (CST) Received: from localhost (10.177.18.62) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Thu, 1 Feb 2018 19:59:41 +0800 From: Gonglei To: Date: Thu, 1 Feb 2018 19:59:32 +0800 Message-ID: <1517486372-22868-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.8.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.32 Subject: [Qemu-devel] [PATCH] vl: fix possible int overflow for qemu_timedate_diff() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, Gonglei , shenghualong Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: shenghualong 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: 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 Signed-off-by: Gonglei --- 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;