From 8deacbc438ca90b4e226141464656b7340d06a4d Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Fri, 18 Feb 2022 02:41:03 +0700 Subject: [PATCH] Allocate (argc + 1) for the service arguments, with calloc It was assumed that getopt checks argc count and does not require null-terminated argv pointer to determine argv end for optional parameter. That is wrong. Add null-terminated latest argv. Fixes #246 --- src/service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 0435bcb..6a9bd19 100644 --- a/src/service.c +++ b/src/service.c @@ -30,7 +30,7 @@ int service_register(int argc, char *argv[]) */ if (!service_argc && !service_argv) { service_argc = argc; - service_argv = malloc(sizeof(void*) * (size_t)argc); + service_argv = calloc(sizeof(void*), (size_t)(argc + 1)); for (i = 0; i < argc; i++) { service_argv[i] = strdup(argv[i]); }