device_attr_show.cocci 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. ///
  3. /// From Documentation/filesystems/sysfs.rst:
  4. /// show() must not use snprintf() when formatting the value to be
  5. /// returned to user space. If you can guarantee that an overflow
  6. /// will never happen you can use sprintf() otherwise you must use
  7. /// scnprintf().
  8. ///
  9. // Confidence: High
  10. // Copyright: (C) 2020 Denis Efremov ISPRAS
  11. // Options: --no-includes --include-headers
  12. //
  13. virtual report
  14. virtual org
  15. virtual context
  16. virtual patch
  17. @r depends on !patch@
  18. identifier show, dev, attr, buf;
  19. position p;
  20. @@
  21. ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
  22. {
  23. <...
  24. * return snprintf@p(...);
  25. ...>
  26. }
  27. @rp depends on patch@
  28. identifier show, dev, attr, buf;
  29. @@
  30. ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
  31. {
  32. <...
  33. return
  34. - snprintf
  35. + scnprintf
  36. (...);
  37. ...>
  38. }
  39. @script: python depends on report@
  40. p << r.p;
  41. @@
  42. coccilib.report.print_report(p[0], "WARNING: use scnprintf or sprintf")
  43. @script: python depends on org@
  44. p << r.p;
  45. @@
  46. coccilib.org.print_todo(p[0], "WARNING: use scnprintf or sprintf")