cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: cocci <cocci@systeme.lip6.fr>
Subject: [Cocci] Coccinelle: Length/Size of char array?
Date: Mon, 02 Aug 2021 10:00:26 -0700	[thread overview]
Message-ID: <ab04588b3b0c2bfa6942beb9069754ce59f2551b.camel@perches.com> (raw)

Is it possible to determine the length of a matched char array and use
the length in a test?

For instance, add something like a test to show only the instances
where a src buffer overruns a dest buffer.

void foo(void)
{
	char foo[5];

	strcpy(foo, "fits");
}

it would be useful to see only the instances where the dest
buffer would be overrun like:

void foo(void)
{
	char foo[5];

	strcpy(foo, "doesn't fit");
}

---

This would find all instances of a constant src array into non-pointer dst:

@@
char [] dest;
constant char [] src;
@@

*	strcpy(dest, src)

---

Is there a mexhanism like:

@@
char [] dest;
constant char [] src;
@@

	when (some cocci grammar testing length(dest) < length(src))
*	strcpy(dest, src)


_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

             reply	other threads:[~2021-08-02 19:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 17:00 Joe Perches [this message]
2021-08-02 17:35 ` [Cocci] Coccinelle: Length/Size of char array? Julia Lawall
2021-08-02 17:43   ` Joe Perches
2021-08-02 18:05     ` Julia Lawall

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=ab04588b3b0c2bfa6942beb9069754ce59f2551b.camel@perches.com \
    --to=joe@perches.com \
    --cc=cocci@systeme.lip6.fr \
    /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).