[PATCH] virsh: fix entering interactive session

Roman Bogorodskiy posted 1 patch 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20260523074235.47341-1-bogorodskiy@gmail.com
tools/virsh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] virsh: fix entering interactive session
Posted by Roman Bogorodskiy 1 week ago
When entering an interactive session, that is, without a command
specified:

  virsh --connect $URI

virsh currently segfaults because it tries to access
ctl->cmd->def->handler and the ctl->cmd is NULL.

Fix by checking if ctl->cmd is not NULL before doing further checks.

Fixes: b489eb8d6b52d4183754a5d1da55006148a331e4
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 tools/virsh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 72d233f98d..401d4f9787 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -126,7 +126,7 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly)
         virErrorPtr err;
         virConnectAuthPtr auth = virConnectAuthPtrDefault;
 
-        if (ctl->cmd->def->handler == cmdComplete) {
+        if (ctl->cmd && ctl->cmd->def->handler == cmdComplete) {
             /* When running from a bash completer we need to avoid any kind of
              * keyboard input (e.g. ssh asking for a password). To achieve
              * this, provide no authentication callbacks. */
-- 
2.52.0
Re: [PATCH] virsh: fix entering interactive session
Posted by Peter Krempa via Devel 5 days, 6 hours ago
On Sat, May 23, 2026 at 09:42:35 +0200, Roman Bogorodskiy wrote:
> When entering an interactive session, that is, without a command
> specified:
> 
>   virsh --connect $URI
> 
> virsh currently segfaults because it tries to access
> ctl->cmd->def->handler and the ctl->cmd is NULL.
> 
> Fix by checking if ctl->cmd is not NULL before doing further checks.
> 
> Fixes: b489eb8d6b52d4183754a5d1da55006148a331e4
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  tools/virsh.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Peter Krempa <pkrempa@redhat.com>

and it should be pushed before we enter freeze!
Re: [PATCH] virsh: fix entering interactive session
Posted by Roman Bogorodskiy 5 days, 5 hours ago
  Peter Krempa wrote:

> On Sat, May 23, 2026 at 09:42:35 +0200, Roman Bogorodskiy wrote:
> > When entering an interactive session, that is, without a command
> > specified:
> > 
> >   virsh --connect $URI
> > 
> > virsh currently segfaults because it tries to access
> > ctl->cmd->def->handler and the ctl->cmd is NULL.
> > 
> > Fix by checking if ctl->cmd is not NULL before doing further checks.
> > 
> > Fixes: b489eb8d6b52d4183754a5d1da55006148a331e4
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > ---
> >  tools/virsh.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 
> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
> 
> and it should be pushed before we enter freeze!

Thanks, pushed!