From a19a3c774e154a4ee537631d42fcd2e20dfd0144 Mon Sep 17 00:00:00 2001 From: Jonas Holmberg Date: Wed, 10 Apr 2019 14:45:36 +0200 Subject: [PATCH] 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 Signed-off-by: Joachim Nilsson --- src/svc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svc.c b/src/svc.c index b167f112..2248b729 100644 --- a/src/svc.c +++ b/src/svc.c @@ -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; }