kmerr.cocci 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /// This semantic patch looks for kmalloc etc that are not followed by a
  2. /// NULL check. It only gives a report in the case where there is some
  3. /// error handling code later in the function, which may be helpful
  4. /// in determining what the error handling code for the call to kmalloc etc
  5. /// should be.
  6. ///
  7. // Confidence: High
  8. // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
  9. // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
  10. // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  11. // URL: http://coccinelle.lip6.fr/
  12. // Comments:
  13. // Options: --no-includes --include-headers
  14. virtual context
  15. virtual org
  16. virtual report
  17. @withtest@
  18. expression x;
  19. position p;
  20. identifier f,fld;
  21. @@
  22. x@p = f(...);
  23. ... when != x->fld
  24. \(x == NULL \| x != NULL\)
  25. @fixed depends on context && !org && !report@
  26. expression x,x1;
  27. position p1 != withtest.p;
  28. statement S;
  29. position any withtest.p;
  30. identifier f;
  31. @@
  32. *x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
  33. ...
  34. *x1@p = f(...);
  35. if (!x1) S
  36. // ------------------------------------------------------------------------
  37. @rfixed depends on (org || report) && !context exists@
  38. expression x,x1;
  39. position p1 != withtest.p;
  40. position p2;
  41. statement S;
  42. position any withtest.p;
  43. identifier f;
  44. @@
  45. x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
  46. ...
  47. x1@p = f@p2(...);
  48. if (!x1) S
  49. @script:python depends on org@
  50. p1 << rfixed.p1;
  51. p2 << rfixed.p2;
  52. @@
  53. cocci.print_main("alloc call",p1)
  54. cocci.print_secs("possible model",p2)
  55. @script:python depends on report@
  56. p1 << rfixed.p1;
  57. p2 << rfixed.p2;
  58. @@
  59. msg = "alloc with no test, possible model on line %s" % (p2[0].line)
  60. coccilib.report.print_report(p1[0],msg)