Fix issue where svc_find() finds the wrong service

This issue may arise in situations where the name of the service being
compared is a sub-string of the service we want to see if it exist.

Example:
  - Two different services: teamd, teamdagentd
  - They have the same id, 1 being the default if none is specified
  - The service with the shortest name is created first

While checking if the "teamdagentd" service exists we eventually compare
it to the "teamd" service.  Prior to this fix we only compare the names
names with the length of the existing service.  Hence, teamdagentd will
seem to be the same as teamd since the first part of the string is equal
to the existing.

Signed-off-by: Jonas Holmberg <jonas.holmberg@westermo.se>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Jonas Holmberg
2020-01-07 13:23:53 +01:00
committed by Joachim Nilsson
parent a4f1330eae
commit a19a3c774e
+1 -1
View File
@@ -300,7 +300,7 @@ svc_t *svc_find(char *cmd, char *id)
svc_t *svc, *iter = NULL;
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (!strcmp(svc->id, id) && !strncmp(svc->cmd, cmd, strlen(svc->cmd)))
if (!strcmp(svc->cmd, cmd) && !strcmp(svc->id, id))
return svc;
}