Fix possible NULL ptr deref, found by Coverity Scan
@@ -1227,7 +1227,11 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (tty_parse_args(cmd, &tty))
return errno;
- len += strlen(tty.cmd) + tty.num + 1;
+ if (tty.cmd)
+ len += strlen(tty.cmd);
+ else
+ len += 3;
+ len += tty.num + 1;
for (i = 0; i < tty.num; i++)
len += strlen(tty.args[i]) + 1;
@@ -1235,7 +1239,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (!line)
return errno;
- snprintf(line, len, "%s", tty.cmd);
+ snprintf(line, len, "%s", tty.cmd ? tty.cmd : "tty");
for (i = 0; i < tty.num; i++) {
strlcat(line, " ", len);
strlcat(line, tty.args[i], len);
