windows: always quote path for windows functions needing it

Ticket: 8600

CreateServiceA doc states for example :

> If the path contains a space, it must be quoted so that it is
  correctly interpreted.

Also fixes strlcat usage and check return value to error out on
truncated path
pull/15676/head
Philippe Antoine 1 month ago committed by Victor Julien
parent 114c80099c
commit ac1b3cc1ef

@ -219,18 +219,29 @@ int SCServiceInstall(int argc, char **argv)
do {
memset(path, 0, sizeof(path));
if (GetModuleFileName(NULL, path, MAX_PATH) == 0 ){
path[0] = '"';
if (GetModuleFileName(NULL, path + 1, sizeof(path) - 1) == 0) {
SCLogError("Can't get path to service binary: %d", (int)GetLastError());
break;
}
if (strlcat(path, "\"", sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
break;
}
/* skip name of binary itself */
for (i = 1; i < argc; i++) {
if ((strlen(argv[i]) <= strlen("--service-install")) && (strncmp("--service-install", argv[i], strlen(argv[i])) == 0)) {
continue;
}
strlcat(path, " ", sizeof(path) - strlen(path) - 1);
strlcat(path, argv[i], sizeof(path) - strlen(path) - 1);
if (strlcat(path, " ", sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
return -1;
}
if (strlcat(path, argv[i], sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
return -1;
}
}
if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) {
@ -344,18 +355,29 @@ int SCServiceChangeParams(int argc, char **argv)
do {
memset(path, 0, sizeof(path));
if (GetModuleFileName(NULL, path, MAX_PATH) == 0 ){
path[0] = '"';
if (GetModuleFileName(NULL, path + 1, sizeof(path) - 1) == 0) {
SCLogError("Can't get path to service binary: %d", (int)GetLastError());
break;
}
if (strlcat(path, "\"", sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
break;
}
/* skip name of binary itself */
for (i = 1; i < argc; i++) {
if ((strlen(argv[i]) <= strlen("--service-change-params")) && (strncmp("--service-change-params", argv[i], strlen(argv[i])) == 0)) {
continue;
}
strlcat(path, " ", sizeof(path) - strlen(path) - 1);
strlcat(path, argv[i], sizeof(path) - strlen(path) - 1);
if (strlcat(path, " ", sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
return -1;
}
if (strlcat(path, argv[i], sizeof(path)) >= sizeof(path)) {
SCLogError("failed to construct service path string: path truncated: %s", path);
return -1;
}
}
if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) {

Loading…
Cancel
Save