From: Christian Brauner Date: Mon, 8 Jan 2018 17:24:41 +0000 (+0100) Subject: coverity: #1427191 X-Git-Tag: lxc-2.0.10~383 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3461599a1f72caf513cc080b76cd6cc396a226c;p=thirdparty%2Flxc.git coverity: #1427191 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 1c2faef28..dab112b15 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2411,15 +2411,17 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, return -1; } - buflen = sizeof("deny\n") - 1; - errno = 0; - ret = lxc_write_nointr(fd, "deny\n", buflen); - if (ret != buflen) { - SYSERROR("Failed to write \"deny\" to \"/proc/%d/setgroups\"", pid); + if (fd >= 0) { + buflen = sizeof("deny\n") - 1; + errno = 0; + ret = lxc_write_nointr(fd, "deny\n", buflen); + if (ret != buflen) { + SYSERROR("Failed to write \"deny\" to \"/proc/%d/setgroups\"", pid); + close(fd); + return -1; + } close(fd); - return -1; } - close(fd); } ret = snprintf(path, MAXPATHLEN, "/proc/%d/%cid_map", pid,