From d6d979bc2b5e1927d281e10419f5b0710c7e78c3 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sat, 9 Dec 2017 19:22:32 +0100 Subject: [PATCH] coverity: #1425867 do not pass NULL pointer to chdir() Signed-off-by: Christian Brauner --- src/lxc/attach.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index c83a4455e..76349f887 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -1186,9 +1186,11 @@ int lxc_attach(const char *name, const char *lxcpath, new_cwd = options->initial_cwd; else new_cwd = cwd; - ret = chdir(new_cwd); - if (ret < 0) - WARN("Could not change directory to \"%s\".", new_cwd); + if (new_cwd) { + ret = chdir(new_cwd); + if (ret < 0) + WARN("Could not change directory to \"%s\"", new_cwd); + } free(cwd); /* Now create the real child process. */