]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nsenter: fix possible NULL dereferece [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 12 Jul 2023 07:56:17 +0000 (09:56 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 12 Jul 2023 08:02:06 +0000 (10:02 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/nsenter.c

index 1c83e35c17010ac6235764758dab0475059581cc..0a3086f53582c4a58568339de03c3d85db788218 100644 (file)
@@ -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++;