Fix possible NULL pointer dereference

When a user sets up a TTY without a device, triggering the tty->notty
code path, the tty->dev will be NULL and tty_parse_args() still return
OK result.

Found by Coverity Scan

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-02-23 10:30:16 +01:00
parent ffd01b0276
commit 9a357b7aab
+13 -10
View File
@@ -1675,6 +1675,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (tty_parse_args(&tty, cmd, &args))
return errno;
/* NOTE: this may result in dev == NULL! */
if (tty_isatcon(tty.dev))
dev = tty_atcon();
else
@@ -1707,17 +1708,19 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
respawn = 1;
/* Create name:id tuple for identity, e.g., tty:S0 */
ptr = strrchr(dev, '/');
if (ptr)
ptr++;
else
ptr = dev;
if (!strncmp(ptr, "tty", 3))
ptr += 3;
if (dev) {
ptr = strrchr(dev, '/');
if (ptr)
ptr++;
else
ptr = dev;
if (!strncmp(ptr, "tty", 3))
ptr += 3;
name = "tty";
if (!id || id[0] == 0)
id = ptr;
name = "tty";
if (!id || id[0] == 0)
id = ptr;
}
svc = svc_find_by_tty(dev);
} else