[cygrunsrv - a wrapper for unix daemons to make them controllable as windows services] branch master, updated. 405add89a98ee2c995c38dbbc47c8b95a2d721d8
Corinna Vinschen via Cygwin-apps-cvs <[email protected]> Mon, 6 Feb 2023 19:47:30 +0000 (GMT)
| Newsgroups | gmane.os.cygwin.cvs.apps |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/cygrunsrv.git;h=405add89a98ee2c995c38dbbc47c8b95a2d721d8 commit 405add89a98ee2c995c38dbbc47c8b95a2d721d8 Author: Corinna Vinschen <[email protected]> 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);