[PATCH 1/4] lxc_controller: Initialize ctrl->handshakeFd properly

Michal Privoznik posted 4 patches 4 years, 9 months ago
[PATCH 1/4] lxc_controller: Initialize ctrl->handshakeFd properly
Posted by Michal Privoznik 4 years, 9 months ago
The lxc_controller has a structure that's keeping its internal
state, including so called handshakeFd which is the write end of
a pipe that's used to signal to the LXC driver that the container
is set up and ready to run. However, the struct member is not
initialized to -1, so if anything fails before it is set then the
virLXCControllerFree() function tries to close FD 0 (stdin).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/lxc/lxc_controller.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index ab5fc8b88f..50b2987d9a 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -193,8 +193,8 @@ static virLXCController *virLXCControllerNew(const char *name)
 
     ctrl->timerShutdown = -1;
     ctrl->firstClient = true;
-
     ctrl->name = g_strdup(name);
+    ctrl->handshakeFd = -1;
 
     if (!(driver = virLXCControllerDriverNew()))
         goto error;
-- 
2.26.3

Re: [PATCH 1/4] lxc_controller: Initialize ctrl->handshakeFd properly
Posted by Martin Kletzander 4 years, 9 months ago
On Tue, Apr 20, 2021 at 04:15:15PM +0200, Michal Privoznik wrote:
>The lxc_controller has a structure that's keeping its internal
>state, including so called handshakeFd which is the write end of
>a pipe that's used to signal to the LXC driver that the container
>is set up and ready to run. However, the struct member is not
>initialized to -1, so if anything fails before it is set then the
>virLXCControllerFree() function tries to close FD 0 (stdin).
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/lxc/lxc_controller.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
>index ab5fc8b88f..50b2987d9a 100644
>--- a/src/lxc/lxc_controller.c
>+++ b/src/lxc/lxc_controller.c
>@@ -193,8 +193,8 @@ static virLXCController *virLXCControllerNew(const char *name)
>
>     ctrl->timerShutdown = -1;
>     ctrl->firstClient = true;
>-
>     ctrl->name = g_strdup(name);
>+    ctrl->handshakeFd = -1;
>
>     if (!(driver = virLXCControllerDriverNew()))
>         goto error;
>-- 
>2.26.3
>