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 committed 2025-02-23 10:30:16 +01:00
1 parent ffd01b0276
commit 9a357b7aab
1 file changed
+3
+3
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)) if (tty_parse_args(&tty, cmd, &args))
return errno; return errno;
/* NOTE: this may result in dev == NULL! */
if (tty_isatcon(tty.dev)) if (tty_isatcon(tty.dev))
dev = tty_atcon(); dev = tty_atcon();
else else
@@ -1707,6 +1708,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
respawn = 1; respawn = 1;
/* Create name:id tuple for identity, e.g., tty:S0 */ /* Create name:id tuple for identity, e.g., tty:S0 */
if (dev) {
ptr = strrchr(dev, '/'); ptr = strrchr(dev, '/');
if (ptr) if (ptr)
ptr++; ptr++;
@@ -1718,6 +1720,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
name = "tty"; name = "tty";
if (!id || id[0] == 0) if (!id || id[0] == 0)
id = ptr; id = ptr;
}
svc = svc_find_by_tty(dev); svc = svc_find_by_tty(dev);
} else } else