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
This commit is contained in:
ValdikSS 2022-02-18 02:41:03 +07:00
parent 1cfd2b1b9f
commit 8deacbc438

View File

@ -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]);
}