qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: pmatouse@redhat.com, aliguori@us.ibm.com, lersek@redhat.com,
	qemu-stable@nongnu.org, lveyde@redhat.com
Subject: [Qemu-devel] [PATCH 2/3] ga_install_service(): nest error paths more idiomatically
Date: Thu, 25 Jul 2013 15:37:23 -0500	[thread overview]
Message-ID: <1374784644-29078-3-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1374784644-29078-1-git-send-email-mdroth@linux.vnet.ibm.com>

From: Laszlo Ersek <lersek@redhat.com>

Acked-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/service-win32.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/qga/service-win32.c b/qga/service-win32.c
index 6de8be4..1cf81fc 100644
--- a/qga/service-win32.c
+++ b/qga/service-win32.c
@@ -38,10 +38,12 @@ static int printf_win_error(const char *text)
 int ga_install_service(const char *path, const char *logfile,
                        const char *state_dir)
 {
+    int ret = EXIT_FAILURE;
     SC_HANDLE manager;
     SC_HANDLE service;
     TCHAR module_fname[MAX_PATH];
     GString *cmdline;
+    SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };
 
     if (GetModuleFileName(NULL, module_fname, MAX_PATH) == 0) {
         printf_win_error("No full path to service's executable");
@@ -66,28 +68,28 @@ int ga_install_service(const char *path, const char *logfile,
     manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if (manager == NULL) {
         printf_win_error("No handle to service control manager");
-        g_string_free(cmdline, TRUE);
-        return EXIT_FAILURE;
+        goto out_strings;
     }
 
     service = CreateService(manager, QGA_SERVICE_NAME, QGA_SERVICE_DISPLAY_NAME,
         SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
         SERVICE_ERROR_NORMAL, cmdline->str, NULL, NULL, NULL, NULL, NULL);
-
-    if (service) {
-        SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };
-        ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);
-
-        fprintf(stderr, "Service was installed successfully.\n");
-    } else {
+    if (service == NULL) {
         printf_win_error("Failed to install service");
+        goto out_manager;
     }
 
+    ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);
+    fprintf(stderr, "Service was installed successfully.\n");
+    ret = EXIT_SUCCESS;
     CloseServiceHandle(service);
+
+out_manager:
     CloseServiceHandle(manager);
 
+out_strings:
     g_string_free(cmdline, TRUE);
-    return (service == NULL);
+    return ret;
 }
 
 int ga_uninstall_service(void)
-- 
1.7.9.5

  parent reply	other threads:[~2013-07-25 20:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 20:37 [Qemu-devel] [PULL 0/3] qemu-ga: security fixes for CVE-2013-2231 Michael Roth
2013-07-25 20:37 ` [Qemu-devel] [PATCH 1/3] qga/service-win32.c: diagnostic output should go to stderr Michael Roth
2013-07-25 20:37 ` Michael Roth [this message]
2013-07-25 20:37 ` [Qemu-devel] [PATCH 3/3] qga: escape cmdline args when registering win32 service (CVE-2013-2231) 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=1374784644-29078-3-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=lersek@redhat.com \
    --cc=lveyde@redhat.com \
    --cc=pmatouse@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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).