Skip to content

Commit

Permalink
Fix possible NULL pointer dereference
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
troglobit committed Feb 23, 2025
1 parent ffd01b0 commit 9a357b7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a357b7

Please sign in to comment.