qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: "Wolfgang Bumiller" <w.bumiller@proxmox.com>,
	"Stefan Reiter" <s.reiter@proxmox.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Thomas Lamprecht" <t.lamprecht@proxmox.com>
Subject: Re: [PATCH v4 2/2] monitor: refactor set/expire_password and allow VNC display id
Date: Mon, 11 Oct 2021 11:17:06 -0500	[thread overview]
Message-ID: <20211011161706.56ycs26qtwhdawmu@redhat.com> (raw)
In-Reply-To: <YWRSJQPJRdGsPXET@work-vm>

On Mon, Oct 11, 2021 at 04:03:01PM +0100, Dr. David Alan Gilbert wrote:
> * Stefan Reiter (s.reiter@proxmox.com) wrote:
> > It is possible to specify more than one VNC server on the command line,
> > either with an explicit ID or the auto-generated ones à la "default",
> > "vnc2", "vnc3", ...
> > 

> > +++ b/monitor/hmp-cmds.c
> > @@ -1451,10 +1451,41 @@ void hmp_set_password(Monitor *mon, const QDict *qdict)
> >  {
> >      const char *protocol  = qdict_get_str(qdict, "protocol");
> >      const char *password  = qdict_get_str(qdict, "password");
> > +    const char *display = qdict_get_try_str(qdict, "display");
> >      const char *connected = qdict_get_try_str(qdict, "connected");
> >      Error *err = NULL;
> > +    DisplayProtocol proto;
> >  
> > -    qmp_set_password(protocol, password, !!connected, connected, &err);
> > +    SetPasswordOptions opts = {
> > +        .password = g_strdup(password),
> 
> You're leaking that strdup on the error returns; you probably want to
> add an error:  exit and goto it to do all the cleanup.

Or maybe there's a way to use g_autofree to let the compiler clean it
up automatically.

> 
> > +        .u.vnc.display = NULL,
> > +    };
> > +
> > +    proto = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
> > +                            DISPLAY_PROTOCOL_VNC, &err);
> > +    if (err) {
> > +        hmp_handle_error(mon, err);
> > +        return;
> > +    }
> > +    opts.protocol = proto;
> > +
> > +    if (proto == DISPLAY_PROTOCOL_VNC) {
> > +        opts.u.vnc.has_display = !!display;
> > +        opts.u.vnc.display = g_strdup(display);
> > +    } else if (proto == DISPLAY_PROTOCOL_SPICE) {
> > +        opts.u.spice.has_connected = !!connected;
> > +        opts.u.spice.connected =
> > +            qapi_enum_parse(&SetPasswordAction_lookup, connected,
> > +                            SET_PASSWORD_ACTION_KEEP, &err);
> > +        if (err) {
> > +            hmp_handle_error(mon, err);
> > +            return;
> > +        }
> > +    }
> > +
> > +    qmp_set_password(&opts, &err);
> > +    g_free(opts.password);
> > +    g_free(opts.u.vnc.display);

Hmm. Why are we hand-cleaning only portions of the QAPI type instead
of using the generated qapi_free_SetPasswordOptions() do to things?

> >      hmp_handle_error(mon, err);
> >  }
> >  
> > @@ -1462,9 +1493,31 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)
> >  {
> >      const char *protocol  = qdict_get_str(qdict, "protocol");
> >      const char *whenstr = qdict_get_str(qdict, "time");
> > +    const char *display = qdict_get_try_str(qdict, "display");
> >      Error *err = NULL;
> > +    DisplayProtocol proto;
> >  
> > -    qmp_expire_password(protocol, whenstr, &err);
> > +    ExpirePasswordOptions opts = {
> > +        .time = g_strdup(whenstr),
> > +        .u.vnc.display = NULL,
> > +    };
> 
> Same here; that 'whenstr' gets leaked on errors.
> 
> > +    proto = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
> > +                            DISPLAY_PROTOCOL_VNC, &err);
> > +    if (err) {
> > +        hmp_handle_error(mon, err);
> > +        return;
> > +    }
> > +    opts.protocol = proto;
> > +
> > +    if (proto == DISPLAY_PROTOCOL_VNC) {
> > +        opts.u.vnc.has_display = !!display;
> > +        opts.u.vnc.display = g_strdup(display);
> > +    }
> > +
> > +    qmp_expire_password(&opts, &err);
> > +    g_free(opts.time);
> > +    g_free(opts.u.vnc.display);
> >      hmp_handle_error(mon, err);

Same here - using the generated qapi_free_ function rather than doing
things by hand, and/or smart use of g_autofree, may make this easier
to maintain.


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2021-10-11 16:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28  9:03 [PATCH v4] VNC-related HMP/QMP fixes Stefan Reiter
2021-09-28  9:03 ` [PATCH v4 1/2] monitor/hmp: add support for flag argument with value Stefan Reiter
2021-10-11 11:39   ` Dr. David Alan Gilbert
2021-09-28  9:03 ` [PATCH v4 2/2] monitor: refactor set/expire_password and allow VNC display id Stefan Reiter
2021-10-11 15:03   ` Dr. David Alan Gilbert
2021-10-11 16:17     ` Eric Blake [this message]
2021-10-12  9:24   ` Markus Armbruster
2021-10-13 16:09     ` Stefan Reiter
2021-10-14  7:14       ` Markus Armbruster
2021-10-14 14:52         ` Stefan Reiter
2021-10-19  5:46           ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011161706.56ycs26qtwhdawmu@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=s.reiter@proxmox.com \
    --cc=t.lamprecht@proxmox.com \
    --cc=w.bumiller@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).