Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// From Documentation/filesystems/sysfs.rst:
0004 ///  show() must not use snprintf() when formatting the value to be
0005 ///  returned to user space. If you can guarantee that an overflow
0006 ///  will never happen you can use sprintf() otherwise you must use
0007 ///  scnprintf().
0008 ///
0009 // Confidence: High
0010 // Copyright: (C) 2020 Denis Efremov ISPRAS
0011 // Options: --no-includes --include-headers
0012 //
0013 
0014 virtual report
0015 virtual org
0016 virtual context
0017 virtual patch
0018 
0019 @r depends on !patch@
0020 identifier show, dev, attr, buf;
0021 position p;
0022 @@
0023 
0024 ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
0025 {
0026         <...
0027 *       return snprintf@p(...);
0028         ...>
0029 }
0030 
0031 @rp depends on patch@
0032 identifier show, dev, attr, buf;
0033 @@
0034 
0035 ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
0036 {
0037         <...
0038         return
0039 -               snprintf
0040 +               scnprintf
0041                         (...);
0042         ...>
0043 }
0044 
0045 @script: python depends on report@
0046 p << r.p;
0047 @@
0048 
0049 coccilib.report.print_report(p[0], "WARNING: use scnprintf or sprintf")
0050 
0051 @script: python depends on org@
0052 p << r.p;
0053 @@
0054 
0055 coccilib.org.print_todo(p[0], "WARNING: use scnprintf or sprintf")