From nobody Sun Dec 14 22:14:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578331810; cv=none; d=zohomail.com; s=zohoarc; b=UJ8wlp5iiGVEeEN9cf6c8KPP/stmObNRZvkPaK9kzsVUmST3Lnp4OBSHiGNUdCp6xM7OvQeRYJVLf8HfNEEKKRoIRREf098BePZs6yOZ7P2/5C0prObE0iJ+0+xwwDgw9P9grE75qO3/k12Lr3V3FpqGO6arK6Fp+rhUvPrGRcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578331810; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+1vS+pDkdQcll/8UHNUKpccqH8tdtuv6X/22nyPneIo=; b=J91TymEwQNCpZflGWTjpUzV0tDzZnzKHlxGrt44SzMsqybd+9fMpZ6oCW5dhUCcMT3BJHUXVggp8lnwXSspdrBJ4pG6lnIae7SNk6Y1y2/FqXuYLoacLb1PhCqJPaLTh4S2jbn6XZn0WZXsjcG0TI85MySiOj8msqAZJH4Fx/Xk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1578331810146614.2131796899012; Mon, 6 Jan 2020 09:30:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-9uX_qcuIN92dq8iNNJOQqA-1; Mon, 06 Jan 2020 12:30:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1867E800D48; Mon, 6 Jan 2020 17:29:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E32535D9D6; Mon, 6 Jan 2020 17:29:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 989E881C7A; Mon, 6 Jan 2020 17:29:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 006HTYQH022174 for ; Mon, 6 Jan 2020 12:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id EE21E858B2; Mon, 6 Jan 2020 17:29:34 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-43.gsslab.fab.redhat.com [10.33.9.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C24B858BA; Mon, 6 Jan 2020 17:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578331809; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+1vS+pDkdQcll/8UHNUKpccqH8tdtuv6X/22nyPneIo=; b=By2KtsYIOV3M4Zjx+I+wmGI3dZ99r1AXOZZDW60M59Sn/F+v2GqRj+YMuVCB3S7sWzOneV RBOXzPjN8NzQEMHweewowThPHZbT4a6jRNDsW82J1dc3JE3gqLwVlC5SAnMIF+cn1sW6sS +HrTs6nwnYkvez5yc80fwQbdKyomd4I= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 6 Jan 2020 17:26:53 +0000 Message-Id: <20200106172655.1946234-6-berrange@redhat.com> In-Reply-To: <20200106172655.1946234-1-berrange@redhat.com> References: <20200106172655.1946234-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/7] src: remove use of g_date_time_new_from_iso8601 function X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 9uX_qcuIN92dq8iNNJOQqA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The g_date_time_new_from_iso8601() function was introduced as a replacement for strptime in commit 810613a60efe3924c536b3663246900bc08910a5 Author: Daniel P. Berrang=C3=A9 Date: Mon Dec 23 15:37:26 2019 +0000 src: replace strptime()/timegm()/mktime() with GDateTime APIs set Unfortunately g_date_time_new_from_iso8601 isn't available until glib 2.56, and backporting it requires alot of code copying and poking at private glib structs. This reverts domain_conf.c back to its original parsing logic prior to 810613a60efe3924c536b3663246900bc08910a5, but using g_date_time_new() instead of gmtime(). The other files are then adapted to follow a similar approach. --- src/conf/domain_conf.c | 28 ++++++++++++++++----- src/esx/esx_vi_types.c | 56 +++++++++++++++++++++++++++++++++++++----- src/vz/vz_sdk.c | 24 ++++++++++++++---- 3 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ee33b7caf0..69967d4cb7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13675,15 +13675,31 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, if (validTo) { g_autoptr(GDateTime) then =3D NULL; g_autoptr(GTimeZone) tz =3D g_time_zone_new_utc(); - - then =3D g_date_time_new_from_iso8601(validTo, tz); - if (!then) { - virReportError(VIR_ERR_INVALID_ARG, - _("password validity time '%s' values out of ra= nge"), validTo); + char *tmp; + int year, mon, mday, hour, min, sec; + + /* Expect: YYYY-MM-DDTHH:MM:SS (%d-%d-%dT%d:%d:%d) eg 2010-11-28T= 14:29:01 */ + if (/* year */ + virStrToLong_i(validTo, &tmp, 10, &year) < 0 || *tmp !=3D '-' = || + /* month */ + virStrToLong_i(tmp+1, &tmp, 10, &mon) < 0 || *tmp !=3D '-' || + /* day */ + virStrToLong_i(tmp+1, &tmp, 10, &mday) < 0 || *tmp !=3D 'T' || + /* hour */ + virStrToLong_i(tmp+1, &tmp, 10, &hour) < 0 || *tmp !=3D ':' || + /* minute */ + virStrToLong_i(tmp+1, &tmp, 10, &min) < 0 || *tmp !=3D ':' || + /* second */ + virStrToLong_i(tmp+1, &tmp, 10, &sec) < 0 || *tmp !=3D '\0') { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse password validity time '%s', ex= pect YYYY-MM-DDTHH:MM:SS"), + validTo); + VIR_FREE(def->passwd); return -1; } =20 - def->validTo =3D (int)g_date_time_to_unix(then); + then =3D g_date_time_new(tz, year, mon, mday, hour, min, sec); + def->validTo =3D (time_t)g_date_time_to_unix(then); def->expires =3D true; } =20 diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 434313dfa4..ad40ddf54b 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1473,8 +1473,10 @@ int esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime, long long *secondsSinceEpoch) { + char *tmp; g_autoptr(GDateTime) then =3D NULL; g_autoptr(GTimeZone) tz =3D NULL; + int year, mon, mday, hour, min, sec, milliseconds; =20 if (!dateTime || !secondsSinceEpoch) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")= ); @@ -1489,22 +1491,64 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime= *dateTime, * * map negative years to 0, since the base for time_t is the year 1970. */ - if (*(dateTime->value) =3D=3D '-') { + if (dateTime->value[0] =3D=3D '-') { *secondsSinceEpoch =3D 0; return 0; } =20 - tz =3D g_time_zone_new_utc(); - then =3D g_date_time_new_from_iso8601(dateTime->value, tz); - - if (!then) { + if (/* year */ + virStrToLong_i(dateTime->value, &tmp, 10, &year) < 0 || *tmp !=3D = '-' || + /* month */ + virStrToLong_i(tmp+1, &tmp, 10, &mon) < 0 || *tmp !=3D '-' || + /* day */ + virStrToLong_i(tmp+1, &tmp, 10, &mday) < 0 || *tmp !=3D 'T' || + /* hour */ + virStrToLong_i(tmp+1, &tmp, 10, &hour) < 0 || *tmp !=3D ':' || + /* minute */ + virStrToLong_i(tmp+1, &tmp, 10, &min) < 0 || *tmp !=3D ':' || + /* second */ + virStrToLong_i(tmp+1, &tmp, 10, &sec) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("xsd:dateTime value '%s' has unexpected format"), dateTime->value); return -1; } =20 - *secondsSinceEpoch =3D g_date_time_to_unix(then); + if (*tmp !=3D '\0') { + /* skip .ssssss part if present */ + if (*tmp =3D=3D '.' && + virStrToLong_i(tmp + 1, &tmp, 10, &milliseconds) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("xsd:dateTime value '%s' has unexpected forma= t"), + dateTime->value); + return -1; + } + + /* parse timezone offset if present. if missing assume UTC */ + if (*tmp =3D=3D '+' || *tmp =3D=3D '-') { + tz =3D g_time_zone_new(tmp); + } else if (STREQ(tmp, "Z")) { + tz =3D g_time_zone_new_utc(); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("xsd:dateTime value '%s' has unexpected forma= t"), + dateTime->value); + return -1; + } + } else { + tz =3D g_time_zone_new_utc(); + } + + /* + * xsd:dateTime represents local time relative to the optional timezone + * given as offset. pretend the local time is in UTC and use timegm in + * order to avoid interference with the timezone to this computer. + * apply timezone correction afterwards, because it's simpler than + * handling all the possible over- and underflows when trying to apply + * it to the tm struct. + */ + then =3D g_date_time_new(tz, year, mon, mday, hour, min, sec); + *secondsSinceEpoch =3D (long long)g_date_time_to_unix(then); =20 return 0; } diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index c98542c244..26e9e38729 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4608,16 +4608,30 @@ static long long prlsdkParseDateTime(const char *str) { g_autoptr(GDateTime) then =3D NULL; - g_autoptr(GTimeZone) tz =3D g_time_zone_new_local(); - - then =3D g_date_time_new_from_iso8601(str, tz); - if (!then) { + g_autoptr(GTimeZone) tz =3D g_time_zone_new_utc(); + char *tmp; + int year, mon, mday, hour, min, sec; + + /* Expect: YYYY-MM-DD HH:MM:SS (%d-%d-%dT%d:%d:%d) eg 2010-11-28 14:2= 9:01 */ + if (/* year */ + virStrToLong_i(str, &tmp, 10, &year) < 0 || *tmp !=3D '-' || + /* month */ + virStrToLong_i(tmp+1, &tmp, 10, &mon) < 0 || *tmp !=3D '-' || + /* day */ + virStrToLong_i(tmp+1, &tmp, 10, &mday) < 0 || *tmp !=3D ' ' || + /* hour */ + virStrToLong_i(tmp+1, &tmp, 10, &hour) < 0 || *tmp !=3D ':' || + /* minute */ + virStrToLong_i(tmp+1, &tmp, 10, &min) < 0 || *tmp !=3D ':' || + /* second */ + virStrToLong_i(tmp+1, &tmp, 10, &sec) < 0 || *tmp !=3D '\0') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected DateTime format: '%s'"), str); return -1; } =20 - return g_date_time_to_unix(then); + then =3D g_date_time_new(tz, year, mon, mday, hour, min, sec); + return (long long)g_date_time_to_unix(then); } =20 static virDomainSnapshotObjListPtr --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list