public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [cygrunsrv - a wrapper for unix daemons to make them controllable as windows services] branch master, updated. 405add89a98ee2c995c38dbbc47c8b95a2d721d8
@ 2023-02-06 19:47 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-02-06 19:47 UTC (permalink / raw)
  To: cygwin-apps-cvs




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/cygrunsrv.git;h=405add89a98ee2c995c38dbbc47c8b95a2d721d8

commit 405add89a98ee2c995c38dbbc47c8b95a2d721d8
Author: Corinna Vinschen <vinschen@redhat.com>
Date:   Mon Feb 6 20:43:38 2023 +0100

    handle quoted service paths sanely


Diff:
---
 cygrunsrv.cc | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/cygrunsrv.cc b/cygrunsrv.cc
index d6fd76008e51..7b550221d191 100644
--- a/cygrunsrv.cc
+++ b/cygrunsrv.cc
@@ -1506,16 +1506,31 @@ list_services (const char *server, bool verbose)
         }
       
       if (!QueryServiceConfig (sh, qsc_buf, QSC_BUF_SIZE, &bytes_needed))
-        fprintf (stderr, "%s: warning: QueryServiceConfig failed for '%s': "
-                 "Win32 error %u\n%s", appname, srv_buf[i].lpServiceName,
-                 (unsigned) GetLastError (), winerror (GetLastError ()));
+	{
+	  fprintf (stderr, "%s: warning: QueryServiceConfig failed for '%s': "
+		   "Win32 error %u\n%s", appname, srv_buf[i].lpServiceName,
+		   (unsigned) GetLastError (), winerror (GetLastError ()));
+	  CloseServiceHandle (sh);
+	  sh = (SC_HANDLE) 0;
+	  continue;
+	}
+      /* The path might be quoted.  Drop the quotes. */
+      char service_path[strlen (qsc_buf->lpBinaryPathName) + 1];
+      char *endptr = stpcpy (service_path, qsc_buf->lpBinaryPathName[0] == '"'
+					   ? qsc_buf->lpBinaryPathName + 1
+					   : qsc_buf->lpBinaryPathName);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+      if (endptr > service_path && endptr[-1] == '"')
+	endptr[-1] = '\0';
+#pragma GCC diagnostic pop
 
       /* is this us? */
-      else if (same_filename (qsc_buf->lpBinaryPathName, mypath))
-        {          
+      if (same_filename (service_path, mypath))
+        {
           if (!verbose)
 	    {
-	      if (strcasecmp (qsc_buf->lpBinaryPathName, mypath))
+	      if (strcasecmp (service_path, mypath))
 		printf ("(%s)\n", srv_buf[i].lpServiceName);
 	      else
 		printf ("%s\n", srv_buf[i].lpServiceName);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-06 19:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-06 19:47 [cygrunsrv - a wrapper for unix daemons to make them controllable as windows services] branch master, updated. 405add89a98ee2c995c38dbbc47c8b95a2d721d8 Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).