qga: win32 guest-set-user-password improvements
cover qga: win32 guest-set-user-password improvements
From: Marc-André Lureau <[email protected]>
Hi,
Laszlo Ersek pointed out a few worthy improvements to the win32 guest-set-user-password command.
Marc-André Lureau (5):
qga: use more idiomatic qemu-style eol operators
qga: use size_t for wcslen() return value
qga: use wide-chars constants for wchar_t comparisons
qga: fix off-by-one length check
qga: check utf8-to-utf16 conversion
qga/commands-win32.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/5 qga: use more idiomatic qemu-style eol operators
From: Marc-André Lureau <[email protected]>
--- qga/commands-win32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qga/commands-win32.c +3 -3
@@ -1248,9 +1248,9 @@ get_net_error_message(gint error)wchar_t *msg =NULL ;int flags, nchars; - flags =FORMAT_MESSAGE_ALLOCATE_BUFFER - |FORMAT_MESSAGE_IGNORE_INSERTS - |FORMAT_MESSAGE_FROM_SYSTEM ; + flags =FORMAT_MESSAGE_ALLOCATE_BUFFER | +FORMAT_MESSAGE_IGNORE_INSERTS | +FORMAT_MESSAGE_FROM_SYSTEM ;if (error >=NERR_BASE && error <=MAX_NERR ) { module =LoadLibraryExW (L"netmsg.dll" ,NULL ,LOAD_LIBRARY_AS_DATAFILE );
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 1/5] qga: use more idiomatic qemu-style eol operators
Quoting [email protected] (2016-02-17 10:47:51)
Quoted 4 lines
From: Marc-André Lureau <[email protected]>
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
Quoted 24 lines
--- qga/commands-win32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)qga/commands-win32.c +3
-3@@ -1248,9 +1248,9 @@ get_net_error_message(gint error)wchar_t *msg =NULL ;int flags, nchars; - flags =FORMAT_MESSAGE_ALLOCATE_BUFFER - |FORMAT_MESSAGE_IGNORE_INSERTS - |FORMAT_MESSAGE_FROM_SYSTEM ; + flags =FORMAT_MESSAGE_ALLOCATE_BUFFER | +FORMAT_MESSAGE_IGNORE_INSERTS | +FORMAT_MESSAGE_FROM_SYSTEM ;if (error >=NERR_BASE && error <=MAX_NERR ) { module =LoadLibraryExW (L"netmsg.dll" ,NULL ,LOAD_LIBRARY_AS_DATAFILE );Signature · 1 line
2.5.0
PATCH 2/5 qga: use size_t for wcslen() return value
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- qga/commands-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
qga/commands-win32.c +2 -1
@@ -1246,7 +1246,8 @@ get_net_error_message(gint error)HMODULE module =NULL ;gchar *retval =NULL ;wchar_t *msg =NULL ; -int flags, nchars; +int flags; +size_t nchars; flags =FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS |
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 2/5] qga: use size_t for wcslen() return value
Quoting [email protected] (2016-02-17 10:47:52)
Quoted 4 lines
From: Marc-André Lureau <[email protected]>
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
Quoted 21 lines
--- qga/commands-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)qga/commands-win32.c +2
-1@@ -1246,7 +1246,8 @@ get_net_error_message(gint error)HMODULE module =NULL ;gchar *retval =NULL ;wchar_t *msg =NULL ; -int flags, nchars; +int flags; +size_t nchars; flags =FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS |Signature · 1 line
2.5.0
PATCH 3/5 qga: use wide-chars constants for wchar_t comparisons
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- qga/commands-win32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
qga/commands-win32.c +4 -2
@@ -1266,8 +1266,10 @@ get_net_error_message(gint error)if (msg !=NULL ) { nchars =wcslen (msg); -if (nchars >2 && msg[nchars-1 ] =='\n' && msg[nchars-2 ] =='\r' ) { - msg[nchars-2 ] ='\0' ; +if (nchars >2 && + msg[nchars -1 ] ==L'\n' && + msg[nchars -2 ] ==L'\r' ) { + msg[nchars -2 ] =L'\0' ; } retval =g_utf16_to_utf8 (msg,-1 ,NULL ,NULL ,NULL );
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 3/5] qga: use wide-chars constants for wchar_t comparisons
Quoting [email protected] (2016-02-17 10:47:53)
Quoted 4 lines
From: Marc-André Lureau <[email protected]>
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
Quoted 24 lines
--- qga/commands-win32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)qga/commands-win32.c +4
-2@@ -1266,8 +1266,10 @@ get_net_error_message(gint error)if (msg !=NULL ) { nchars =wcslen (msg); -if (nchars >2 && msg[nchars-1 ] =='\n' && msg[nchars-2 ] =='\r' ) { - msg[nchars-2 ] ='\0' ; +if (nchars >2 && + msg[nchars -1 ] ==L'\n' && + msg[nchars -2 ] ==L'\r' ) { + msg[nchars -2 ] =L'\0' ; } retval =g_utf16_to_utf8 (msg,-1 ,NULL ,NULL ,NULL );Signature · 1 line
2.5.0
PATCH 4/5 qga: fix off-by-one length check
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Laszlo Ersek said: "The length check is off by one (in the safe direction); it should be (nchars >= 2). The processing should be active for the wide string L"\r\n" -- resulting in the empty wide string --, I believe."
--- qga/commands-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-win32.c +1 -1
@@ -1266,7 +1266,7 @@ get_net_error_message(gint error)if (msg !=NULL ) { nchars =wcslen (msg); -if (nchars >2 && +if (nchars >=2 && msg[nchars -1 ] ==L'\n' && msg[nchars -2 ] ==L'\r' ) { msg[nchars -2 ] =L'\0' ;
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 4/5] qga: fix off-by-one length check
Quoting [email protected] (2016-02-17 10:47:54)
Quoted 8 lines
From: Marc-André Lureau <[email protected]>
Laszlo Ersek said: "The length check is off by one (in the safe direction); it should be (nchars >= 2). The processing should be active for the wide string L"\r\n" -- resulting in the empty wide string --, I believe."
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
Quoted 20 lines
--- qga/commands-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qga/commands-win32.c +1
-1@@ -1266,7 +1266,7 @@ get_net_error_message(gint error)if (msg !=NULL ) { nchars =wcslen (msg); -if (nchars >2 && +if (nchars >=2 && msg[nchars -1 ] ==L'\n' && msg[nchars -2 ] ==L'\r' ) { msg[nchars -2 ] =L'\0' ;Signature · 1 line
2.5.0
PATCH 5/5 qga: check utf8-to-utf16 conversion
In reply to [email protected]From: Marc-André Lureau <[email protected]>
UTF8 to UTF16 conversion can fail for genuine reasons, let's check errors.
--- qga/commands-win32.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
qga/commands-win32.c +16 -3
@@ -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);
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 5/5] qga: check utf8-to-utf16 conversion
Quoting [email protected] (2016-02-17 10:47:55)
Quoted 6 lines
From: Marc-André Lureau <[email protected]>
UTF8 to UTF16 conversion can fail for genuine reasons, let's check errors.
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
Quoted 52 lines
--- qga/commands-win32.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)qga/commands-win32.c +16
-3@@ -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);Signature · 1 line
2.5.0
Quoted 14 lines · On 02/17/16 17:47, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Hi,
Laszlo Ersek pointed out a few worthy improvements to the win32 guest-set-user-password command.
Marc-André Lureau (5):
qga: use more idiomatic qemu-style eol operators
qga: usesize_tforwcslen()return value
qga: use wide-chars constants forwchar_tcomparisons
qga: fix off-by-one length check
qga: check utf8-to-utf16 conversion
Quoted 3 lines
qga/commands-win32.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
series
Thanks!
Laszlo
Michael Roth
AppliedQuoting [email protected] (2016-02-17 10:47:50)
Quoted 7 lines
From: Marc-André Lureau <[email protected]>
Hi,
Laszlo Ersek pointed out a few worthy improvements to the win32 guest-set-user-password command.
Quoted 6 lines
Marc-André Lureau (5):
qga: use more idiomatic qemu-style eol operators
qga: usesize_tforwcslen()return value
qga: use wide-chars constants forwchar_tcomparisons
qga: fix off-by-one length check
qga: check utf8-to-utf16 conversion
Thanks, applied to qga tree:
https://github.com/mdroth/qemu/commits/qga
Quoted 7 lines
qga/commands-win32.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)Signature · 1 line
2.5.0