Skip to content

Instantly share code, notes, and snippets.

@regit
Created April 26, 2017 11:56
Show Gist options
  • Save regit/d9a186f6ce57b4c669644c3ca05dca32 to your computer and use it in GitHub Desktop.
Save regit/d9a186f6ce57b4c669644c3ca05dca32 to your computer and use it in GitHub Desktop.
Checking memset
@malloced@
expression x;
position p1;
identifier func =~ "(calloc|malloc)";
@@
x@p1 = func(...)
@memset depends on malloced exists@
expression x;
position p2;
@@
memset(&x, ...)@p2
@script:python depends on memset@
p1 << memset.p2;
@@
print "Memset on address of pointer at %s:%s." % (p1[0].file, p1[0].line)
import sys
sys.exit(1)
@regit
Copy link
Author

regit commented Apr 26, 2017

To test code, you need to run

spatch -sp_file memset.cocci src/test.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment