qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jens Freimann <jfreimann@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	Victor Kaplansky <victork@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Marc-Andr?? Lureau <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/5] net: fix -netdev socket, fd= for UDP sockets
Date: Mon, 6 Nov 2017 11:49:14 +0100	[thread overview]
Message-ID: <20171106104914.w2tcqgog2e7jfi2e@localhost.localdomain> (raw)
In-Reply-To: <CAFEAcA96q_ebN06WE5mgOqiPprufR3aVOgkFBhgKKyjFr=aiCA@mail.gmail.com>

On Fri, Nov 03, 2017 at 06:46:57PM +0000, Peter Maydell wrote:
>On 8 August 2017 at 21:38, Jens Freimann <jfreimann@redhat.com> wrote:
>> @@ -333,8 +333,13 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
>>       * by ONLY ONE process: we must "clone" this dgram socket --jjo
>>       */
>>
>> -    if (is_connected) {
>> -        if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) {
>> +    if (is_connected && mcast != NULL) {
>
>This changes the condition() under which we fill in the struct sockaddr_in saddr
>from "if (is_connected)" to "if (is_connected && mcast != NULL)"...
>
>> +            if (parse_host_port(&saddr, mcast) < 0) {
>> +                fprintf(stderr,
>> +                        "qemu: error: init_dgram: fd=%d failed parse_host_port()\n",
>> +                        fd);
>> +                goto err;
>> +            }
>>              /* must be bound */
>>              if (saddr.sin_addr.s_addr == 0) {
>>                  fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, "
>
>...but later in the function we do:
>
>    /* mcast: save bound address as dst */
>    if (is_connected) {

This should be changed to "if (is_connected && mcast != NULL)" because
it is only necessary to do this if there is a multicast address specified. 

>        s->dgram_dst = saddr;
>        snprintf(nc->info_str, sizeof(nc->info_str),
>                 "socket: fd=%d (cloned mcast=%s:%d)",
>                 fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
>    } else {
>        snprintf(nc->info_str, sizeof(nc->info_str),
>                 "socket: fd=%d", fd);
>    }
>
>and coverity correctly points out that if is_connected is true
>but mcast is NULL then we use 'saddr' without having initialized
>it properly.
>
>Any suggestions for the correct fix for this?

I think we should initialize saddr to 0 and do the above change. I'll send a
patch.

Thanks!

regards,
Jens 

  reply	other threads:[~2017-11-06 10:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 20:38 [Qemu-devel] [PATCH v2 0/5] tests/pxe-test: add testcase using vhost-user-bridge Jens Freimann
2017-08-08 20:38 ` [Qemu-devel] [PATCH v2 1/5] tests/vhost-user-bridge: disable debug output by default Jens Freimann
2017-08-08 20:38 ` [Qemu-devel] [PATCH v2 2/5] net: fix -netdev socket, fd= for UDP sockets Jens Freimann
2017-11-03 18:46   ` Peter Maydell
2017-11-06 10:49     ` Jens Freimann [this message]
2017-08-08 20:38 ` [Qemu-devel] [PATCH v2 3/5] libvhost-user: quit when no more data received Jens Freimann
2017-09-19 16:46   ` Marc-André Lureau
2017-09-20 15:09     ` Jens Freimann
2017-09-20 16:14       ` Marc-André Lureau
2017-09-21 13:31         ` Jens Freimann
2017-09-21 16:05           ` Jens Freimann
2017-08-08 20:38 ` [Qemu-devel] [PATCH v2 4/5] libqtest: always set up signal handler for SIGABRT Jens Freimann
2017-08-08 20:39 ` [Qemu-devel] [PATCH v2 5/5] tests/pxe-test: add testcase using vhost-user-bridge Jens Freimann
2017-08-08 21:05 ` [Qemu-devel] [PATCH for-2.10? v2 0/5] " Eric Blake
2017-08-08 22:18   ` Michael S. Tsirkin
2017-08-08 23:59 ` [Qemu-devel] [PATCH " no-reply
2017-08-09  1:17   ` Michael S. Tsirkin
2017-08-09  8:21     ` Jens Freimann

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=20171106104914.w2tcqgog2e7jfi2e@localhost.localdomain \
    --to=jfreimann@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=victork@redhat.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).