size_t.cocci 798 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. @sizet@
  2. size_t p;
  3. identifier func =~ "^(sprintf|printf|SCLog.*)$";
  4. identifier funcn =~ "^.*nprintf$";
  5. position p1;
  6. typedef uint16_t;
  7. typedef uint32_t;
  8. typedef uint64_t;
  9. expression E1, E2;
  10. @@
  11. (
  12. func(..., p, ...)@p1;
  13. |
  14. func(..., (int) p, ...)@p1;
  15. |
  16. func(..., (unsigned int) p, ...)@p1;
  17. |
  18. func(..., (uint16_t) p, ...)@p1;
  19. |
  20. func(..., (uint32_t) p, ...)@p1;
  21. |
  22. func(..., (uint64_t) p, ...)@p1;
  23. |
  24. funcn(E1, E2,..., p, ...)@p1;
  25. |
  26. funcn(E1, E2,..., (int) p, ...)@p1;
  27. |
  28. funcn(E1, E2,..., (unsigned int) p, ...)@p1;
  29. |
  30. funcn(E1, E2,..., (uint16_t) p, ...)@p1;
  31. |
  32. funcn(E1, E2,..., (uint32_t) p, ...)@p1;
  33. |
  34. funcn(E1, E2,..., (uint64_t) p, ...)@p1;
  35. )
  36. @ script:python @
  37. p1 << sizet.p1;
  38. @@
  39. print("Invalid printf with size_t (not casted to uintmax_t) at %s:%s" % (p1[0].file, p1[0].line))
  40. import sys
  41. sys.exit(1)