From: Karel Zak Date: Wed, 12 Jul 2023 07:56:17 +0000 (+0200) Subject: nsenter: fix possible NULL dereferece [coverity scan] X-Git-Tag: v2.40-rc1~336 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ceb540628611210efe1606c8f83cd9f48d0f83f;p=thirdparty%2Futil-linux.git nsenter: fix possible NULL dereferece [coverity scan] Signed-off-by: Karel Zak --- diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index 1c83e35c17..0a3086f535 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -209,8 +209,8 @@ static int get_ns_ino(const char *path, ino_t *ino) static void open_cgroup_procs(void) { - char *buf = NULL, *path = NULL; - int cgroup_fd; + char *buf = NULL, *path = NULL, *p; + int cgroup_fd = 0; char fdpath[PATH_MAX]; open_target_fd(&cgroup_fd, "cgroup", optarg); @@ -218,7 +218,9 @@ static void open_cgroup_procs(void) if (read_all_alloc(cgroup_fd, &buf) < 1) err(EXIT_FAILURE, _("failed to get cgroup path")); - path = strrchr(strtok(buf, "\n"), ':'); + p = strtok(buf, "\n"); + if (p) + path = strrchr(p, ':'); if (!path) err(EXIT_FAILURE, _("failed to get cgroup path")); path++;