From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYbWf-0007ML-Ds for qemu-devel@nongnu.org; Wed, 24 Feb 2016 10:38:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYbWa-00085T-4t for qemu-devel@nongnu.org; Wed, 24 Feb 2016 10:38:53 -0500 Received: from mail-ob0-x241.google.com ([2607:f8b0:4003:c01::241]:33493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYbWa-00085P-05 for qemu-devel@nongnu.org; Wed, 24 Feb 2016 10:38:48 -0500 Received: by mail-ob0-x241.google.com with SMTP id hl1so1193798obc.0 for ; Wed, 24 Feb 2016 07:38:47 -0800 (PST) Sender: fluxion Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1455727675-20625-6-git-send-email-marcandre.lureau@redhat.com> References: <1455727675-20625-1-git-send-email-marcandre.lureau@redhat.com> <1455727675-20625-6-git-send-email-marcandre.lureau@redhat.com> Message-ID: <20160224153838.29588.20168@loki> Date: Wed, 24 Feb 2016 09:38:38 -0600 Subject: Re: [Qemu-devel] [PATCH 5/5] qga: check utf8-to-utf16 conversion List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: lersek@redhat.com Quoting marcandre.lureau@redhat.com (2016-02-17 10:47:55) > From: Marc-Andr=C3=A9 Lureau > = > UTF8 to UTF16 conversion can fail for genuine reasons, let's check errors. > = > Reported-by: Laszlo Ersek > Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Michael Roth > --- > qga/commands-win32.c | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > = > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > index ae8cf3d..09ed465 100644 > --- a/qga/commands-win32.c > +++ b/qga/commands-win32.c > @@ -1292,8 +1292,9 @@ void qmp_guest_set_user_password(const char *userna= me, > NET_API_STATUS nas; > char *rawpasswddata =3D NULL; > size_t rawpasswdlen; > - wchar_t *user, *wpass; > + wchar_t *user =3D NULL, *wpass =3D NULL; > USER_INFO_1003 pi1003 =3D { 0, }; > + GError *gerr =3D NULL; > = > if (crypted) { > error_setg(errp, QERR_UNSUPPORTED); > @@ -1307,8 +1308,15 @@ void qmp_guest_set_user_password(const char *usern= ame, > rawpasswddata =3D g_renew(char, rawpasswddata, rawpasswdlen + 1); > rawpasswddata[rawpasswdlen] =3D '\0'; > = > - user =3D g_utf8_to_utf16(username, -1, NULL, NULL, NULL); > - wpass =3D g_utf8_to_utf16(rawpasswddata, -1, NULL, NULL, NULL); > + user =3D g_utf8_to_utf16(username, -1, NULL, NULL, &gerr); > + if (!user) { > + goto done; > + } > + > + wpass =3D g_utf8_to_utf16(rawpasswddata, -1, NULL, NULL, &gerr); > + if (!wpass) { > + goto done; > + } > = > pi1003.usri1003_password =3D wpass; > nas =3D NetUserSetInfo(NULL, user, > @@ -1321,6 +1329,11 @@ void qmp_guest_set_user_password(const char *usern= ame, > g_free(msg); > } > = > +done: > + if (gerr) { > + error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message); > + g_error_free(gerr); > + } > g_free(user); > g_free(wpass); > g_free(rawpasswddata); > -- = > 2.5.0 >=20