qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org
Cc: lersek@redhat.com
Subject: Re: [Qemu-devel] [PATCH 5/5] qga: check utf8-to-utf16 conversion
Date: Wed, 24 Feb 2016 09:38:38 -0600	[thread overview]
Message-ID: <20160224153838.29588.20168@loki> (raw)
In-Reply-To: <1455727675-20625-6-git-send-email-marcandre.lureau@redhat.com>

Quoting marcandre.lureau@redhat.com (2016-02-17 10:47:55)
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> UTF8 to UTF16 conversion can fail for genuine reasons, let's check errors.
> 
> Reported-by: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  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 *username,
>      NET_API_STATUS nas;
>      char *rawpasswddata = NULL;
>      size_t rawpasswdlen;
> -    wchar_t *user, *wpass;
> +    wchar_t *user = NULL, *wpass = NULL;
>      USER_INFO_1003 pi1003 = { 0, };
> +    GError *gerr = NULL;
> 
>      if (crypted) {
>          error_setg(errp, QERR_UNSUPPORTED);
> @@ -1307,8 +1308,15 @@ void qmp_guest_set_user_password(const char *username,
>      rawpasswddata = g_renew(char, rawpasswddata, rawpasswdlen + 1);
>      rawpasswddata[rawpasswdlen] = '\0';
> 
> -    user = g_utf8_to_utf16(username, -1, NULL, NULL, NULL);
> -    wpass = g_utf8_to_utf16(rawpasswddata, -1, NULL, NULL, NULL);
> +    user = g_utf8_to_utf16(username, -1, NULL, NULL, &gerr);
> +    if (!user) {
> +        goto done;
> +    }
> +
> +    wpass = g_utf8_to_utf16(rawpasswddata, -1, NULL, NULL, &gerr);
> +    if (!wpass) {
> +        goto done;
> +    }
> 
>      pi1003.usri1003_password = wpass;
>      nas = NetUserSetInfo(NULL, user,
> @@ -1321,6 +1329,11 @@ void qmp_guest_set_user_password(const char *username,
>          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
> 

  reply	other threads:[~2016-02-24 15:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 16:47 [Qemu-devel] [PATCH 0/5] qga: win32 guest-set-user-password improvements marcandre.lureau
2016-02-17 16:47 ` [Qemu-devel] [PATCH 1/5] qga: use more idiomatic qemu-style eol operators marcandre.lureau
2016-02-24 15:34   ` Michael Roth
2016-02-17 16:47 ` [Qemu-devel] [PATCH 2/5] qga: use size_t for wcslen() return value marcandre.lureau
2016-02-24 15:34   ` Michael Roth
2016-02-17 16:47 ` [Qemu-devel] [PATCH 3/5] qga: use wide-chars constants for wchar_t comparisons marcandre.lureau
2016-02-24 15:35   ` Michael Roth
2016-02-17 16:47 ` [Qemu-devel] [PATCH 4/5] qga: fix off-by-one length check marcandre.lureau
2016-02-24 15:37   ` Michael Roth
2016-02-17 16:47 ` [Qemu-devel] [PATCH 5/5] qga: check utf8-to-utf16 conversion marcandre.lureau
2016-02-24 15:38   ` Michael Roth [this message]
2016-02-17 17:02 ` [Qemu-devel] [PATCH 0/5] qga: win32 guest-set-user-password improvements Laszlo Ersek
2016-02-25  2:09 ` Michael Roth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160224153838.29588.20168@loki \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=lersek@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).