qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Simon <qemu.bugs@whitewinterwolf.com>
Subject: Re: [Qemu-devel] [PATCH] sockets: report error if UNIX socket path is too long
Date: Wed, 24 May 2017 11:00:05 -0500	[thread overview]
Message-ID: <de9edf69-282b-f12e-4868-493e1b4faf40@redhat.com> (raw)
In-Reply-To: <4706484e-b8dc-b8a8-d33f-48d82302d59b@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1629 bytes --]

On 05/24/2017 10:54 AM, Eric Blake wrote:
> On 05/24/2017 10:42 AM, Daniel P. Berrange wrote:
>> The 'struct sockaddr_un' only allows 108 bytes for the socket
>> path. Currently QEMU uses snprintf() and so silently truncates
>> the socket path provided by the user. This is undesirable because
>> the user will then be unable to connect to the path they asked
>> for. This change makes QEMU bounds check and report an explicit
>> error message.
>>
>> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
>> ---
>>  util/qemu-sockets.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>

>>          snprintf(un.sun_path, sizeof(un.sun_path), "%s", saddr->path);
> 
> Pre-existing, but now that we know things fit, isn't it faster to use
> strcpy (or strpcpy or strncpy) instead of the overhead of snprintf?
> 
> You're on the right track, but it may be worth a v2 for further cleanups.

Oh, and while there, I noticed:

        tmpdir = tmpdir ? tmpdir : "/tmp";
        if (snprintf(un.sun_path, sizeof(un.sun_path),
"%s/qemu-socket-XXXXXX",
                     tmpdir) >= sizeof(un.sun_path)) {
            error_setg_errno(errp, errno,
                             "TMPDIR environment variable (%s) too
large", tmpdir);

but 'errno' is NOT required to be set when snprintf() returns a larger
value, so our error message is (likely) garbage.  Better might be
calling error_setg_errno(errp, ENAMETOOLONG, ...), or just living with
the simpler error_setg().

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

      reply	other threads:[~2017-05-24 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 15:42 [Qemu-devel] [PATCH] sockets: report error if UNIX socket path is too long Daniel P. Berrange
2017-05-24 15:54 ` Eric Blake
2017-05-24 16:00   ` Eric Blake [this message]

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=de9edf69-282b-f12e-4868-493e1b4faf40@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu.bugs@whitewinterwolf.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).