]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: init file descriptors to -EBADF 3638/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 15:36:52 +0000 (16:36 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 15:38:17 +0000 (16:38 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index ea9a018b9cc2b6c6a7d612a71935291088c7a7e1..8a42e6ce4e87463ed28ebeb75e2894f1424a18b1 100644 (file)
@@ -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)