From: Jan Kiszka <jan.kiszka@web.de>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Stefan Weil <sw@weilnetz.de>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] slirp: Fix error reported by static code analysis and remove wrong type casts
Date: Tue, 04 Sep 2012 09:27:35 +0200 [thread overview]
Message-ID: <5045AD67.7040300@web.de> (raw)
In-Reply-To: <CAFEAcA_X9S7_rQ6u6gB1JTfgMLuhA-UiN-Y2h4WN8SnjcpRFgg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1735 bytes --]
On 2012-09-03 23:08, Peter Maydell wrote:
> On 3 September 2012 21:34, Stefan Weil <sw@weilnetz.de> wrote:
>> Report from smatch:
>> slirp/tcp_subr.c:127 tcp_respond(17) error:
>> we previously assumed 'tp' could be null (see line 124)
>>
>> Fix this by checking 'tp' before reading its elements.
>>
>> The type casts of pointers to long are not related to the smatch report
>> but happened to be near that code. Those type casts are not allowed
>> when sizeof(pointer) != sizeof(long).
>
> I think these would be better in a separate patch.
>> @@ -124,7 +124,7 @@ tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m,
>> if (tp)
>> win = sbspace(&tp->t_socket->so_rcv);
>> if (m == NULL) {
>> - if ((m = m_get(tp->t_socket->slirp)) == NULL)
>> + if (tp && (m = m_get(tp->t_socket->slirp)) == NULL)
>> return;
>> tlen = 0;
>> m->m_data += IF_MAXLINKHDR;
>
> This doesn't look quite right -- now if tp is NULL we will skip
> the assignment to m and dereference a NULL pointer a few lines
> further on, right?
This would be correct:
if (!tp || ..)
return
>
> I suspect that we need either to be passed our Slirp* explicitly rather
> than via tp, or we have to enforce that tcp_respond() is called with
> a non-NULL struct tcpcb*. I think the only cases where tp can be non-NULL
> at the moment are the two calls from the dropwithreset code in tcp_input().
Indeed, this is a "XXX Should never fail" case - according to the code
that checks tp at the call site. But as no one seriously understands
slirp details, we are better safe than sorry.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
next prev parent reply other threads:[~2012-09-04 7:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 20:34 [Qemu-devel] [PATCH] slirp: Fix error reported by static code analysis and remove wrong type casts Stefan Weil
2012-09-03 21:08 ` Peter Maydell
2012-09-04 7:27 ` Jan Kiszka [this message]
2012-09-04 7:49 ` Peter Maydell
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=5045AD67.7040300@web.de \
--to=jan.kiszka@web.de \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.