From patchwork Sun Jul 5 14:28:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 491317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 27DCA140D4D for ; Mon, 6 Jul 2015 00:29:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=jpQaDkj7; dkim-atps=neutral Received: from localhost ([::1]:46832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBkvA-00025w-Ae for incoming@patchwork.ozlabs.org; Sun, 05 Jul 2015 10:29:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBkut-0001hV-JE for qemu-devel@nongnu.org; Sun, 05 Jul 2015 10:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBkuo-00006m-J3 for qemu-devel@nongnu.org; Sun, 05 Jul 2015 10:29:11 -0400 Received: from mail-qk0-x231.google.com ([2607:f8b0:400d:c09::231]:32861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBkuo-00006T-F2 for qemu-devel@nongnu.org; Sun, 05 Jul 2015 10:29:06 -0400 Received: by qkhu186 with SMTP id u186so102477514qkh.0 for ; Sun, 05 Jul 2015 07:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=Par5ZKY6DR5IDIBfK9+CrgCnwTyFNIGbFbDdpvWsXS0=; b=jpQaDkj7ySohF+dGEcdF0ZT7sR5/8Iu/s8LnboY3pSeL4e77hdobqTbMeq2mXLxhKI 9Cs7BCi9NiiviMM7HAcXbC/b068QvElWcSTO6pljnGVMmpmVXC88z1tBY5xvVgrKG/o3 FXAekGwt9cFHLcFNRyt5sNLLKReZx8Zp48M7ZKfJXaSHkQXvwtS4MrQKcXELq79ukReZ bDZrthm9GvGE7acSSGOFbtimwx07GS+/4JKBZsB74/jLNVOQrMKhy1O8+GWdMaipdx6z BE1St90v6wIbjEdiWo3r0aBwKttrVQiaEhxuZQioCAFf/EEJlFwi56s9bjdqC/UPfwb1 zfrg== X-Received: by 10.140.96.116 with SMTP id j107mr45164917qge.20.1436106545205; Sun, 05 Jul 2015 07:29:05 -0700 (PDT) Received: from localhost (206.Red-88-1-125.dynamicIP.rima-tde.net. [88.1.125.206]) by mx.google.com with ESMTPSA id l33sm7780072qkh.12.2015.07.05.07.29.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Jul 2015 07:29:04 -0700 (PDT) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sun, 5 Jul 2015 16:28:58 +0200 Message-Id: <1436106538-32692-1-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c09::231 Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH] qga: fail early for invalid time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's possible to set system time with dates after 2070, however, it's not possible to set the RTC. It has limitation to up to year 2070 (1970+100). In order to keep both clock in sync and before the kernel complains on invalid values, bail out early. Signed-off-by: Marc-André Lureau --- qga/commands-posix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index befd00b..d8847be 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -154,6 +154,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) /* If user has passed a time, validate and set it. */ if (has_time) { + GDate date = { 0, }; + /* year-2038 will overflow in case time_t is 32bit */ if (time_ns / 1000000000 != (time_t)(time_ns / 1000000000)) { error_setg(errp, "Time %" PRId64 " is too large", time_ns); @@ -162,6 +164,11 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) tv.tv_sec = time_ns / 1000000000; tv.tv_usec = (time_ns % 1000000000) / 1000; + g_date_set_time_t(&date, tv.tv_sec); + if (date.year < 1970 || date.year >= 2070) { + error_setg_errno(errp, errno, "Invalid time"); + return; + } ret = settimeofday(&tv, NULL); if (ret < 0) {