From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFQlt-0002Kj-8Q for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:05:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFQlm-00037s-Gq for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:05:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFQlm-00037i-8h for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:05:38 -0400 Message-ID: <513F441E.1010509@redhat.com> Date: Tue, 12 Mar 2013 09:05:02 -0600 From: Eric Blake MIME-Version: 1.0 References: <1363079306-27589-1-git-send-email-lilei@linux.vnet.ibm.com> <1363079306-27589-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1363079306-27589-3-git-send-email-lilei@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2OGMIXJAMOMQNCQAFRBPG" Subject: Re: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lei Li Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2OGMIXJAMOMQNCQAFRBPG Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/12/2013 03:08 AM, Lei Li wrote: > Signed-off-by: Lei Li > --- > qga/commands-win32.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) >=20 > +void qmp_guest_set_time(int64_t time_ns, Error **errp) > +{ > + SYSTEMTIME ts; > + FILETIME tf; > + LONGLONG time; > + > + acquire_privilege(SE_SYSTEMTIME_NAME, errp); > + if (error_is_set(errp)) { > + error_setg(errp, "Failed to acquire privilege"); > + return; > + } Earlier, you told me that acquire_privilege is auto-dropped after a successful SetSystemTime. But here, you acquire the privilege... > + > + if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) { > + error_setg(errp, "Time %" PRId64 "is invalid", time_ns); > + return; =2E..then return early without ever relinquishing it. > + } > + > + time =3D time_ns / 100 + W32_FT_OFFSET; > + > + tf.dwLowDateTime =3D (DWORD) time; > + tf.dwHighDateTime =3D (DWORD) (time >> 32); > + > + if (!FileTimeToSystemTime(&tf, &ts)) { > + error_setg(errp, "Failed to convert system time"); > + return; > + } I would reorder the acquire_privilege to here, to give us the best possible chance of avoiding a leak of privileges when the user passes bogus data. > + > + if (!SetSystemTime(&ts)) { > + slog("guest-set-time failed: %d", GetLastError()); > + error_setg_errno(errp, errno, "Failed to set time to guest"); > + return; > + } > +} > + > int64_t qmp_guest_file_open(const char *path, bool has_mode, const cha= r *mode, Error **err) > { > error_set(err, QERR_UNSUPPORTED); >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2OGMIXJAMOMQNCQAFRBPG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRP0QeAAoJEKeha0olJ0NqTzYH/0l1fYBaCBfzUux/EPWT3YPL Sc/TygmnR+PJ3ggW0MW6Nah0DlRvK7Xfj3+ftE7T6rkYhK/9yBVBRkxdxQarVJdg xhdpk4IHBXReoV0mmfJ10jHb2HfL3b+tFK+xmOgt461ivtghJ/UIIE6QQpDXryBV CCtE5KmoI7evahts5m7pmOwEo5MgwvJU4PkmRuDMxHSiXcCVMmaHrrbKulnD+jAm nWs9qMKjcqy7VDirwVEw7FT5E/ilLnkf9kKGbKmL9zOtMHw1F9fWBA/4fp3DzwzQ 7fnoawhUZeEj2P+Qov8SQD1FT45RVVj/LFZQ7k0kuwzc8M5nUrbtUuUIWY0jIMY= =RiNA -----END PGP SIGNATURE----- ------enig2OGMIXJAMOMQNCQAFRBPG--