From: Christian Brauner Date: Fri, 29 Jan 2021 15:36:52 +0000 (+0100) Subject: attach: init file descriptors to -EBADF X-Git-Tag: lxc-5.0.0~313^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=581b849a74c33598b24440220dc17e5ca0e946ff;p=thirdparty%2Flxc.git attach: init file descriptors to -EBADF Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index ea9a018b9..8a42e6ce4 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -91,7 +91,19 @@ static inline bool sync_wait_fd(int fd, int *fd_recv) static struct attach_context *alloc_attach_context(void) { - return zalloc(sizeof(struct attach_context)); + struct attach_context *ctx; + + ctx = zalloc(sizeof(struct attach_context)); + if (!ctx) + return ret_set_errno(NULL, ENOMEM); + + ctx->dfd_self_pid = -EBADF; + ctx->dfd_init_pid = -EBADF; + + for (int i = 0; i < LXC_NS_MAX; i++) + ctx->ns_fd[i] = -EBADF; + + return ctx; } static int get_personality(const char *name, const char *lxcpath, @@ -174,8 +186,6 @@ static int get_attach_context(struct attach_context *ctx, /* Move to file descriptor-only lsm label retrieval. */ ctx->lsm_label = ctx->lsm_ops->process_label_get(ctx->lsm_ops, ctx->init_pid); ctx->ns_inherited = 0; - for (int i = 0; i < LXC_NS_MAX; i++) - ctx->ns_fd[i] = -EBADF; ret = get_personality(container->name, container->config_path, &ctx->personality); if (ret)