From e51587c66ef19d93c22ef76af2eb8f6207d7d440 Mon Sep 17 00:00:00 2001 From: Ming Liu Date: Thu, 3 Feb 2022 17:10:46 +0100 Subject: [PATCH 1/2] initctl.c: change string_match to string_compare It should not use relaxed comparison in some places, otherwise it mess up with scenarios like: ``` $ initctl status ntpdpre $ initctl status ntpd ``` the output might be same for both of the above commands without this fix. Signed-off-by: Ming Liu --- src/initctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index 6d0c6488..786f6435 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -722,7 +722,7 @@ static int show_status(char *arg) for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { svc_ident(svc, ident, sizeof(ident)); - if (string_match(ident, arg)) + if (string_compare(ident, arg)) num++; if (string_case_compare(ident, arg)) exact++; @@ -797,7 +797,7 @@ static int show_status(char *arg) char *lvls; svc_ident(svc, ident, sizeof(ident)); - if (num && !string_match(ident, arg)) + if (num && !string_compare(ident, arg)) continue; printf("%-*d ", pw, svc->pid); @@ -995,7 +995,7 @@ static int cmd_parse(int argc, char *argv[], struct cmd *command) if (!cmd_cond(&command[i])) continue; - if (!string_match(command[i].cmd, argv[0])) + if (!string_compare(command[i].cmd, argv[0])) continue; if (command[i].ctx) From cfffcd4513808ef12bc9e82083dd50f98d65aec7 Mon Sep 17 00:00:00 2001 From: Ming Liu Date: Fri, 4 Feb 2022 15:05:00 +0100 Subject: [PATCH 2/2] svc.c: change strncmp to string_compare strncmp can not handle the case when name is a substring of cmd. Signed-off-by: Ming Liu --- src/svc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svc.c b/src/svc.c index 209b0158..ae61e880 100644 --- a/src/svc.c +++ b/src/svc.c @@ -256,7 +256,7 @@ svc_t *svc_named_iterator(svc_t **iter, int first, char *cmd) for (svc = svc_iterator(iter, first); svc; svc = svc_iterator(iter, 0)) { char *name = svc->name; - if (!strncmp(name, cmd, strlen(name))) + if (string_compare(name, cmd)) return svc; }