public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <der.herr@hofr.at>
To: kernel-janitors@vger.kernel.org
Subject: Re: type mismatch
Date: Mon, 11 May 2015 08:29:29 +0000	[thread overview]
Message-ID: <20150511082929.GA24018@opentech.at> (raw)
In-Reply-To: <alpine.DEB.2.10.1505101517100.2645@hadrien>

On Mon, 11 May 2015, Julia Lawall wrote:

> 
> 
> On Mon, 11 May 2015, Nicholas Mc Guire wrote:
> 
> > On Sun, 10 May 2015, Dan Carpenter wrote:
> > 
> > > I don't really have a strong opinion either way...  It's unlikely that
> > > we will introduce a bug here and if we did, I think it would be caught
> > > immediately in testing.
> > > 
> > > It's pretty common to treat the first member of a struct as special.
> > > What annoys me is when people do
> > > 
> > > struct foo {
> > > 	int one, two, three;
> > > 	whatever;
> > > };
> > > 
> > > memcpy(&foo.one, src, sizoef(struct foo));
> > > 
> > > Argh!?  These triger buffer overflows warnings in Smatch and I don't
> > > see the point since &foo.one is less readable than &foo!  Oh well, I
> > > think these were common enough, I had to treat it as idiomatic and add a
> > > special case for them.
> > >
> > just ran a naive scanner for that pattern but only could find this one instance
> > 
> > ./net/sctp/sm_make_chunk.c:3103 ugly memset 
> > 3102          if (af->is_any(&addr))
> > 3103                  memcpy(&addr.v4, sctp_source(asconf), sizeof(addr));
> > 
> > my scanner ist:
> > 
> > @uses_first@
> > identifier f;
> > idexpression s;
> 
> Maybe generalize s (ie expression) and the size (ie, don't specify 
> anything)?  The sizeof could be a type also.
>
yup - adding the type check case finds two additional cases
but generalizing s to an expression did not change results

@uses_first@
identifier f;
type T;
idexpression T s;
identifier e;
position p;
@@

f(...){
<+...
(
* memcpy@p(&s.e,...,sizeof(s));
|
* memcpy@p(&s.e,...,sizeof(T));
)
...+>
}

./drivers/infiniband/hw/ehca/ehca_mcast.c:80 ugly memset
./drivers/infiniband/hw/ehca/ehca_mcast.c:117 ugly memset
./net/sctp/sm_make_chunk.c:3103 ugly memset

thx!
hofrat

      parent reply	other threads:[~2015-05-11  8:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-10 13:20 type mismatch Julia Lawall
2015-05-10 19:57 ` Dan Carpenter
2015-05-10 20:03 ` Julia Lawall
2015-05-11  7:18 ` Nicholas Mc Guire
2015-05-11  7:32 ` Julia Lawall
2015-05-11  8:14 ` Dan Carpenter
2015-05-11  8:29 ` Nicholas Mc Guire [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=20150511082929.GA24018@opentech.at \
    --to=der.herr@hofr.at \
    --cc=kernel-janitors@vger.kernel.org \
    /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