├── rosecheckers ├── test │ ├── 09_cpp.h │ ├── PRE09.h │ ├── lib1.h │ ├── lib1_cpp.h │ ├── lib2.h │ ├── lib2_cpp.h │ ├── my_stdio.h │ ├── stdio.h │ ├── my_stdio_cpp.h │ ├── stdio_cpp.h │ ├── PRE08_library1.h │ ├── PRE08_library1_cpp.h │ ├── PRE08_library2.h │ ├── PRE08_library2_cpp.h │ ├── c.cce.wiki.DCL.ans │ ├── c.cce.wiki.ENV.ans │ ├── c.cce.wiki.ERR.ans │ ├── c.cce.wiki.FLP.ans │ ├── c.cce.wiki.POS.ans │ ├── c.cce.wiki.PRE.ans │ ├── c.cce.wiki.SIG.ans │ ├── c.cce.xtra.ARR.ans │ ├── c.cce.xtra.DCL.ans │ ├── c.cce.xtra.MSC.ans │ ├── c.ncce.wiki.PRE.ans │ ├── cpp.cce.wiki.ARR.ans │ ├── cpp.cce.wiki.DCL.ans │ ├── cpp.cce.wiki.ENV.ans │ ├── cpp.cce.wiki.ERR.ans │ ├── cpp.cce.wiki.FLP.ans │ ├── cpp.cce.wiki.INT.ans │ ├── cpp.cce.wiki.OBJ.ans │ ├── cpp.cce.wiki.PRE.ans │ ├── cpp.cce.wiki.SIG.ans │ ├── cpp.cce.wiki.STR.ans │ ├── c.ncce.xtra.ARR.ans │ ├── cpp.ncce.wiki.ARR.ans │ ├── cpp.ncce.wiki.DCL.ans │ ├── cpp.ncce.wiki.ENV.ans │ ├── cpp.ncce.wiki.FIO.ans │ ├── cpp.ncce.wiki.FLP.ans │ ├── cpp.ncce.wiki.INT.ans │ ├── cpp.ncce.wiki.MEM.ans │ ├── cpp.ncce.wiki.OBJ.ans │ ├── cpp.ncce.wiki.PRE.ans │ ├── cpp.ncce.wiki.SIG.ans │ ├── cpp.ncce.wiki.STR.ans │ ├── 06_CPP.h │ ├── PRE06_NCCE.h │ ├── PRE06_CS.h │ ├── c.cce.xtra.EXP.ans │ ├── PRE06_CS_CPP.h │ ├── c.ncce.xtra.FLP.ans │ ├── c.cce.wiki.ARR.ans │ ├── c.ncce.xtra.MEM.ans │ ├── cpp.cce.wiki.EXP.ans │ ├── cpp.cce.wiki.MEM.ans │ ├── c.cce.wiki.MSC.ans │ ├── c.ncce.xtra.MSC.ans │ ├── c.cce.wiki.EXP.ans │ ├── cpp.ncce.wiki.EXP.ans │ ├── c.cce.wiki.INT.ans │ ├── c.cce.wiki.MEM.ans │ ├── c.ncce.xtra.POS.ans │ ├── c.cce.wiki.STR.ans │ ├── c.cce.xtra.POS.ans │ ├── cpp.cce.wiki.FIO.ans │ ├── c.ncce.wiki.ERR.ans │ ├── c.ncce.xtra.INT.ans │ ├── c.cce.wiki.FIO.ans │ ├── c.ncce.wiki.POS.ans │ ├── cpp.ncce.wiki.ERR.ans │ ├── c.ncce.xtra.EXP.ans │ ├── c.ncce.wiki.DCL.ans │ ├── c.ncce.xtra.DCL.ans │ ├── cpp.lib.ERR.h │ ├── cpp.lib.FIO.h │ ├── c.ncce.wiki.ARR.ans │ ├── c.ncce.wiki.SIG.ans │ ├── c.ncce.wiki.MSC.ans │ ├── c.ncce.wiki.FLP.ans │ ├── c.ncce.wiki.ENV.ans │ ├── c.ncce.xtra.FLP.c │ ├── c.cce.xtra.ARR.c │ ├── c.ncce.xtra.ARR.c │ ├── c.ncce.xtra.INT.c │ ├── c.ncce.xtra.MSC.c │ ├── c.cce.xtra.MSC.c │ ├── c.cce.xtra.DCL.c │ ├── c.ncce.wiki.MEM.ans │ ├── c.ncce.xtra.POS.c │ ├── c.ncce.wiki.INT.ans │ ├── c.ncce.xtra.DCL.c │ ├── c.ncce.wiki.STR.ans │ ├── c.ncce.xtra.EXP.c │ ├── c.ncce.wiki.FIO.ans │ ├── c.ncce.xtra.MEM.c │ ├── c.ncce.wiki.EXP.ans │ ├── util.h │ ├── cpp.util.h │ ├── c.cce.xtra.EXP.c │ ├── c.cce.xtra.POS.c │ ├── c.cce.wiki.ERR.c │ ├── cpp.ncce.wiki.ENV.C │ ├── c.ncce.wiki.ERR.c │ ├── cpp.cce.wiki.SIG.C │ ├── c.ncce.wiki.POS.c │ ├── cpp.ncce.wiki.SIG.C │ ├── cpp.cce.wiki.ENV.C │ └── c.ncce.wiki.FLP.c ├── .gdbinit ├── example.c ├── value.h ├── gcc_as_rosecheckers ├── g++_as_rosecheckers ├── PRE.C ├── test_next_visitor.c ├── categories.h ├── virtualCFG.C ├── Dockerfile ├── .project ├── license.txt └── categories.C ├── README.md ├── license.txt ├── tags └── jpcert-080805 │ └── c_rules │ ├── cce │ ├── PRE09.h │ ├── PRE08_lib1.h │ ├── PRE08_lib2.h │ ├── my_stdio.h │ ├── PRE06_CS.h │ ├── util.h │ └── ERR_CS.c │ ├── ncce │ ├── stdio.h │ ├── PRE08_library1.h │ ├── PRE08_library2.h │ ├── PRE06_NCCE.h │ ├── util.h │ ├── NCCE.c │ ├── ERR_NCCE.c │ ├── POS_NCCE.c │ ├── FLP_NCCE.c │ ├── ARR_NCCE.c │ └── ENV_NCCE.c │ ├── .gdbinit │ ├── graphs │ ├── foo.png │ ├── AST.xml.gz │ ├── foo_WholeAST.png │ ├── STR31_C_getenv.c │ └── foo.c │ ├── diagnose.sh │ ├── gcc_diagnose │ ├── test_next_visitor.c │ ├── cce.ans │ ├── value.h │ ├── example.c │ ├── PRE.C │ ├── categories.h │ ├── README │ ├── diagnose.C │ ├── ERR.C │ ├── Makefile │ └── categories.C ├── .gitignore └── cpp_rules ├── test_cstring.C ├── test_iostream.C ├── test_others.C ├── CPlusPlus_Rules_Implemented_in_Rose_files ├── 1off.jpg ├── 2off.jpg ├── 3off.jpg ├── 4off.jpg ├── 5off.jpg ├── wait.gif ├── 1pxinv.gif ├── add_16.gif ├── docs_16.gif ├── securec.jpg ├── cert_logo.gif ├── cylab_alt.jpg ├── print_16.gif ├── star_grey.gif ├── watch_16.gif ├── add_page_16.gif ├── browse_space.gif ├── uscert_4g_sm.jpg ├── add_comment_16.gif ├── sei_cmu_logo2.gif └── add_blogentry_16.gif ├── testOBJ03A.C ├── testOBJ01A.C ├── testEXP04A.C ├── testEXP02A.C ├── testEXP03A.C ├── testEXP38C.C ├── testERR01A.C ├── testEXP09A.C ├── testOBJ04A.C ├── testOBJ32C.C ├── testDCL32C.C ├── testERR02A.C ├── testEXP08A.C ├── testOBJ02A.C ├── FLP.C ├── testOBJ00A.C ├── testEXP36C.C ├── diagnose.C ├── testRES35C.C ├── testEXP10A.C ├── Makefile └── RES.C /rosecheckers/test/09_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE09.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/lib1.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/lib1_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/lib2.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/lib2_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/my_stdio.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/stdio.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | rosecheckers/README.md -------------------------------------------------------------------------------- /rosecheckers/test/my_stdio_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/stdio_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | rosecheckers/license.txt -------------------------------------------------------------------------------- /rosecheckers/test/PRE08_library1.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE08_library1_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE08_library2.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE08_library2_cpp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.DCL.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.ENV.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.ERR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.FLP.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.POS.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.PRE.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.SIG.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.ARR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.DCL.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.MSC.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.PRE.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.ARR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.DCL.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.ENV.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.ERR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.FLP.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.INT.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.OBJ.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.PRE.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.SIG.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.STR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/PRE09.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | rosecheckers/.ccls-cache/ 2 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.ARR.ans: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.ARR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.DCL.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.ENV.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.FIO.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.FLP.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.INT.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.MEM.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.OBJ.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.PRE.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.SIG.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.STR.ans: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/PRE08_lib1.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/PRE08_lib2.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/my_stdio.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/stdio.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/PRE08_library1.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/PRE08_library2.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rosecheckers/test/06_CPP.h: -------------------------------------------------------------------------------- 1 | /* anything here */ 2 | -------------------------------------------------------------------------------- /rosecheckers/.gdbinit: -------------------------------------------------------------------------------- 1 | set print static-members off 2 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE06_NCCE.h: -------------------------------------------------------------------------------- 1 | /* anything here */ 2 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/.gdbinit: -------------------------------------------------------------------------------- 1 | set print static-members off 2 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/PRE06_NCCE.h: -------------------------------------------------------------------------------- 1 | /* anything here */ 2 | -------------------------------------------------------------------------------- /cpp_rules/test_cstring.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /cpp_rules/test_iostream.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE06_CS.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_H 2 | #define HEADER_H 3 | 4 | /* anything here */ 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.EXP.ans: -------------------------------------------------------------------------------- 1 | c.cce.xtra.EXP.c:66: warning: EXP05-C: Do not cast away a const qualification 2 | -------------------------------------------------------------------------------- /rosecheckers/test/PRE06_CS_CPP.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_H 2 | #define HEADER_H 3 | 4 | /* anything here */ 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/PRE06_CS.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_H 2 | #define HEADER_H 3 | 4 | /* anything here */ 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.FLP.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.FLP.c:21: error: FLP30-C: Do not use floating point variables as loop counters 2 | -------------------------------------------------------------------------------- /cpp_rules/test_others.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.ARR.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.ARR.c:105: warning: MEM08-C: Use realloc() only to resize dynamically allocated arrays 2 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.MEM.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.MEM.c:38: error: MEM34-C: Only free memory allocated dynamically 2 | some error on MEM34 3 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.EXP.ans: -------------------------------------------------------------------------------- 1 | cpp.cce.wiki.EXP.C:169: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.MEM.ans: -------------------------------------------------------------------------------- 1 | cpp.cce.wiki.MEM.C:144: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/graphs/foo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/tags/jpcert-080805/c_rules/graphs/foo.png -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.MSC.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.MSC.c:165: warning: INT07-C: Use only explicitly signed or unsigned char type for numeric values 2 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/diagnose.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | libtool --mode=execute /home/svoboda/Desktop/Documents/Work/c_rules/diagnose $* || true 3 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/graphs/AST.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/tags/jpcert-080805/c_rules/graphs/AST.xml.gz -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/graphs/foo_WholeAST.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/tags/jpcert-080805/c_rules/graphs/foo_WholeAST.png -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.MSC.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.MSC.c:24: warning: MSC03-C: Avoid errors of addition 2 | c.ncce.xtra.MSC.c:28: warning: MSC03-C: Avoid errors of addition 3 | -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/1off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/1off.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/2off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/2off.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/3off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/3off.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/4off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/4off.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/5off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/5off.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/wait.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/wait.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/1pxinv.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/1pxinv.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/docs_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/docs_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/securec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/securec.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/cert_logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/cert_logo.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/cylab_alt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/cylab_alt.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/print_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/print_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/star_grey.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/star_grey.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/watch_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/watch_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_page_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_page_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/browse_space.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/browse_space.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/uscert_4g_sm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/uscert_4g_sm.jpg -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_comment_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_comment_16.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/sei_cmu_logo2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/sei_cmu_logo2.gif -------------------------------------------------------------------------------- /cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_blogentry_16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmu-sei/cert-rosecheckers/HEAD/cpp_rules/CPlusPlus_Rules_Implemented_in_Rose_files/add_blogentry_16.gif -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.EXP.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.EXP.c:204: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | c.cce.wiki.EXP.c:269: warning: EXP12-C: Do not ignore values returned by functions: rename 3 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.EXP.ans: -------------------------------------------------------------------------------- 1 | cpp.ncce.wiki.EXP.C:74: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | cpp.ncce.wiki.EXP.C:77: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 3 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/graphs/STR31_C_getenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | /* ... */ 6 | char buff[256]; 7 | strcpy(buff, getenv("EDITOR")); 8 | /* ... */ 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.INT.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.INT.c:346: error: INT32-C: Ensure that operations on signed integers do not result in overflow 2 | c.cce.wiki.INT.c:372: error: INT34-C: Do not shift a negative number of bits or more bits than exist in the operand 3 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.MEM.ans: -------------------------------------------------------------------------------- 1 | "./test/c.cce.wiki.MEM.c", line 348: warning: variable "b" was declared but never referenced 2 | char *b; 3 | ^ 4 | c.cce.wiki.MEM.c:254: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 5 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/graphs/foo.c: -------------------------------------------------------------------------------- 1 | char* strcpy(char*, char*); 2 | char* getenv(char*); 3 | 4 | int main(int argc, char** argv) { 5 | /* ... */ 6 | char buff[256]; 7 | strcpy(buff, getenv("EDITOR")); 8 | /* ... */ 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.POS.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.POS.c:22: error: POS34-C: Do not call putenv() with an automatic variable 2 | c.ncce.xtra.POS.c:22: warning: EXP05-C: Do not cast away a const qualification 3 | c.ncce.xtra.POS.c:33: error: POS34-C: Do not call putenv() with an automatic variable 4 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.STR.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.STR.c:62: error: STR31-C: String copy destination must contain sufficient storage 2 | c.cce.wiki.STR.c:195: warning: MSC03-C: Avoid errors of addition 3 | c.cce.wiki.STR.c:222: warning: INT01-C: Use rsize_t or size_t for all integer values representing the size of an object 4 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.POS.ans: -------------------------------------------------------------------------------- 1 | c.cce.xtra.POS.c:25: warning: MEM07-C: Ensure that the arguments to calloc() when multiplied can be represented as a size_t 2 | c.cce.xtra.POS.c:50: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 3 | c.cce.xtra.POS.c:70: warning: EXP05-C: Do not cast away a const qualification 4 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.FIO.ans: -------------------------------------------------------------------------------- 1 | cpp.cce.wiki.FIO.C:683: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | cpp.cce.wiki.FIO.C:846: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 3 | cpp.cce.wiki.FIO.C:930: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 4 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.ERR.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.ERR.c:56: error: FIO42-C: Ensure files are properly closed when they are no longer needed 2 | c.ncce.wiki.ERR.c:62: warning: ERR06-C: Understand the termination behavior of assert() and abort() 3 | c.ncce.wiki.ERR.c:116: error: SIG30-C: Call only asynchronous-safe functions within signal handlers: perror 4 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.INT.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.INT.c:21: warning: INT09-C: Ensure enumeration constants map to unique values 2 | c.ncce.xtra.INT.c:27: error: INT33-C: Ensure that division and modulo operations do not result in divide-by-zero errors 3 | c.ncce.xtra.INT.c:28: error: INT33-C: Ensure that division and modulo operations do not result in divide-by-zero errors 4 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.FIO.ans: -------------------------------------------------------------------------------- 1 | c.cce.wiki.FIO.c:494: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 2 | c.cce.wiki.FIO.c:571: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 3 | c.cce.wiki.FIO.c:689: warning: MSC03-C: Avoid errors of addition 4 | c.cce.wiki.FIO.c:865: warning: ENV04-C: Do not use system() or popen() unless you need a command interpreter 5 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/gcc_diagnose: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | DIAGNOSE="/home/svoboda/Desktop/Documents/Work/c_rules/diagnose --edg:brief_diagnostics " 4 | LD_LIBRARY_PATH=/home/svoboda/Desktop/Documents/Work/rose/compileTree/lib 5 | 6 | gcc -Wall -o nul -S $* > ./.syntax_diagnostics 2>&1 7 | if [ -s ./.syntax_diagnostics ]; then 8 | cat ./.syntax_diagnostics 9 | else 10 | $DIAGNOSE $* 11 | fi 12 | rm ./.syntax_diagnostics || true 13 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.POS.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.POS.c:41: error: POS30-C: Use the readlink() function properly 2 | c.ncce.wiki.POS.c:51: error: POS33-C: Do not use vfork() 3 | c.ncce.wiki.POS.c:70: error: POS34-C: Do not call putenv() with an automatic variable 4 | c.ncce.wiki.POS.c:93: error: POS35-C: Avoid race conditions while checking for the existence of a symbolic link 5 | c.ncce.wiki.POS.c:113: error: POS36-C: Observe correct revocation order while relinquishing privileges 6 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.ERR.ans: -------------------------------------------------------------------------------- 1 | cpp.ncce.wiki.ERR.C:38: warning: ERR08-CPP: Only catch or throw special-purpose exception objects. 2 | cpp.ncce.wiki.ERR.C:40: warning: ERR08-CPP: Do not catch or throw pointers. 3 | cpp.ncce.wiki.ERR.C:42: warning: ERR08-CPP: Only catch or throw special-purpose exception objects. 4 | cpp.ncce.wiki.ERR.C:44: warning: ERR08-CPP: Do not catch or throw pointers. 5 | cpp.ncce.wiki.ERR.C:46: warning: ERR08-CPP: Do not catch or throw classes (except standard exceptions). 6 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.EXP.ans: -------------------------------------------------------------------------------- 1 | c.ncce.xtra.EXP.c:21: warning: EXP09-C: malloc called using something other than sizeof() 2 | c.ncce.xtra.EXP.c:23: warning: EXP09-C: malloc called using something other than sizeof() 3 | c.ncce.xtra.EXP.c:28: warning: EXP09-C: malloc called using something other than sizeof() 4 | c.ncce.xtra.EXP.c:35: warning: EXP09-C: malloc called using something other than sizeof() 5 | c.ncce.xtra.EXP.c:44: error: EXP30-C: Do not depend on order of evaluation between sequence points 6 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ03A.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ03-A. Prefer not to overload virtual functions 3 | 4 | Overloading of virtual functions tends to defeat polymorphism and introduce unnecessary complexity into a class hierarchy. 5 | */ 6 | 7 | class Thing { 8 | public: 9 | virtual ~Thing(); 10 | virtual void update( int ); 11 | virtual void update( double ); 12 | // ... 13 | }; 14 | class MyThing : public Thing { 15 | public: 16 | void update( int ); // overrides only update(int), hides both! 17 | // ... 18 | }; 19 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ01A.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ01-A. Be careful with the definition of conversion operators 3 | 4 | A user-defined type conversion operator can be used to implicitly convert an object to another type. This may lead to unexpected behavior and undesirable results. If user-defined conversions are required, they should be defined as functions, rather than operators, so that they have to be called explicitly. 5 | */ 6 | 7 | class Widget { 8 | public: 9 | operator int() const; 10 | operator short() const; 11 | // ... 12 | }; 13 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.DCL.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.DCL.c:197: error: DCL31-C: Guarantee that mutually visible identifiers are unique: global_symbol_definition_lookup_table_b 2 | c.ncce.wiki.DCL.c:55: warning: DCL00-C: Const-qualify immutable objects: pi 3 | c.ncce.wiki.DCL.c:59: warning: FLP03-C: Detect and handle floating point errors 4 | c.ncce.wiki.DCL.c:69: warning: DCL02-C: Use visually distinct identifiers: DCL01_msg 5 | c.ncce.wiki.DCL.c:69: warning: DCL01-C: Do not reuse variable names in subscopes: DCL01_msg 6 | c.ncce.wiki.DCL.c:103: warning: DCL05-C: Use typedefs to improve code readability 7 | -------------------------------------------------------------------------------- /cpp_rules/testEXP04A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP04-A. Do not overload the comma operator 3 | Added by Fred Long, last edited by Justin Pincar on Sep 12, 2007 (view change) show comment hide comment 4 | 5 | The built in comma operator guarantees that the first operand is evaluated before the second operand. However, if the comma operator is overloaded, its operand evaluation depends on C++'s function parameter mechanism, which does not guarantee the order of evaluation. Therefore, to avoid possibly confusing behavior, the comma operator should not be overloaded. 6 | */ 7 | 8 | class X { 9 | void operator ,( const X & ); 10 | }; 11 | 12 | X operator ,( const X &, int ); 13 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.DCL.ans: -------------------------------------------------------------------------------- 1 | "./test/c.ncce.xtra.DCL.c", line 21: warning: variable "tmp" was declared but never referenced 2 | int tmp=1; 3 | ^ 4 | 5 | c.ncce.xtra.DCL.c:31: warning: DCL02-C: Use visually distinct identifiers: note1 6 | c.ncce.xtra.DCL.c:39: warning: DCL02-C: Use visually distinct identifiers: nome 7 | c.ncce.xtra.DCL.c:21: warning: DCL00-C: Const-qualify immutable objects: tmp 8 | c.ncce.xtra.DCL.c:23: warning: DCL02-C: Use visually distinct identifiers: tmp 9 | c.ncce.xtra.DCL.c:23: warning: DCL00-C: Const-qualify immutable objects: tmp 10 | c.ncce.xtra.DCL.c:23: warning: DCL01-C: Do not reuse variable names in subscopes: tmp 11 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.lib.ERR.h: -------------------------------------------------------------------------------- 1 | typedef void (*constraint_handler_t) ( 2 | const char * __restrict__ msg, 3 | void * __restrict__ ptr, 4 | errno_t error); 5 | 6 | typedef void (*abort_handler_s) ( 7 | const char * __restrict__ msg, 8 | void * __restrict__ ptr, 9 | errno_t error); 10 | 11 | class StackUnderflow : public std::exception { 12 | /* ... */ 13 | public: 14 | StackUnderflow() {}; 15 | void modify() {}; 16 | }; 17 | 18 | // classes used for exception handling 19 | class ERR36_B {}; 20 | class ERR36_D: public ERR36_B {}; 21 | 22 | class ERR37_exception1 : public exception {}; 23 | class ERR37_exception2 : public exception {}; 24 | -------------------------------------------------------------------------------- /cpp_rules/testEXP02A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP02-A. Do not overload the logical AND and OR operators 3 | Added by Fred Long, last edited by Justin Pincar on Sep 12, 2007 (view change) show comment hide comment 4 | 5 | The logical AND and logical OR operators (&&, ||) exhibit "short circuit" operation. That is, the second operand is not evaluated if the result can be deduced solely by evaluating the first operand. However, short-circuit evaluation is not possible for overloaded versions of these operators. Therefore, to avoid possibly confusing behavior, these operators should not be overloaded. 6 | */ 7 | 8 | class X { 9 | X &operator ||( int ); 10 | }; 11 | 12 | bool operator &&( const X &, const X & ); 13 | -------------------------------------------------------------------------------- /cpp_rules/testEXP03A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP03-A. Do not overload the & operator 3 | 4 | 5 | The C++ standard [ISO/IEC 14882-2003] says in Section 5.3.1 paragraph 4 that 6 | 7 | The address of an object of incomplete type can be taken, but if the complete type of that object is a class type that declares operator&() as a member function, then the behavior is undefined (and no diagnostic is required). 8 | 9 | Therefore, to avoid possible undefined behavior, the operator & should not be overloaded. 10 | */ 11 | 12 | class X { 13 | X *operator &(); // diagnostic 14 | bool operator &( const X & ); // no diagnostic 15 | }; 16 | 17 | X *operator &( const X & ); // diagnostic 18 | X *operator &( const X &, const X & ); // no diagnostic 19 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/test_next_visitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This routine is strictly for testing the visit_next function; it should 4 | // visit nodes in the order of i = 1, 2, 3 ... 5 | 6 | void foo() { 7 | char* x = NULL; 8 | int i = 0; 9 | while (i == -1) { 10 | i = -2; 11 | } 12 | 13 | for (i = -3; i == -4; i++) { 14 | i = -5; 15 | } 16 | 17 | for (i = -3; i == 5; i++) { 18 | i = 6; 19 | do { 20 | i = 3; 21 | free(x); 22 | i = 1; 23 | } while (i == 2); 24 | i = 4; 25 | } 26 | 27 | while (i == 7) { 28 | i = 8; 29 | if (i == 9) { 30 | i = 10; 31 | return; 32 | } 33 | i == 11; 34 | } 35 | 36 | 37 | for (i = 12; i == 13; i++) { 38 | i = 14; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.lib.FIO.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define BUFFERSIZE 10 9 | 10 | int verify_file(char *const filename) { 11 | /* Get /etc/passwd entry for current user */ 12 | struct passwd *pwd = getpwuid(getuid()); 13 | if (pwd == NULL) { 14 | /* Handle error */ 15 | return 0; 16 | } 17 | 18 | const unsigned int len = strlen( pwd->pw_dir); 19 | if (strncmp( filename, pwd->pw_dir, len) != 0) { 20 | return 0; 21 | } 22 | /* Make sure there is only one '/', immediately after homedir */ 23 | if (strrchr( filename, '/') == filename + len) { 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /cpp_rules/testEXP38C.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP38-C. Avoid calling your own virtual functions in constructors and destructors. 3 | */ 4 | 5 | class B { 6 | public: 7 | B() { seize(); } // diagnostic 8 | virtual ~B() { release(); } // diagnostic 9 | protected: 10 | virtual void seize() {} 11 | virtual void release() {} 12 | private: 13 | B( const B & ); 14 | B &operator =( const B & ); 15 | }; 16 | 17 | class D : public B { 18 | public: 19 | D() {} 20 | ~D() {} 21 | protected: 22 | void seize() { 23 | B::seize(); 24 | // get derived resources... 25 | } 26 | void release() { 27 | // release derived resources... 28 | B::release(); 29 | } 30 | private: 31 | D( const D & ); 32 | D &operator =( const D & ); 33 | }; 34 | -------------------------------------------------------------------------------- /cpp_rules/testERR01A.C: -------------------------------------------------------------------------------- 1 | /* 2 | ERR01-A. Prefer special-purpose types for exceptions 3 | 4 | Because an exception is caught by its type, rather than its value, it is best to throw objects of special-purpose types that describe the nature of the exception being thrown. Throwing objects of more general-purpose types, particularly predefined types, makes code hard to understand and maintain, and defeats much of the advantage of the C++ exception-handling mechanism. 5 | */ 6 | 7 | extern void doSomething(); 8 | 9 | struct X {}; 10 | 11 | void f() { 12 | try { 13 | doSomething(); 14 | } 15 | catch( char const *msg ) // diagnostic 16 | {} 17 | catch( int x ) // diagnostic 18 | {} 19 | catch( int (*fp)() ) // diagnostic 20 | {} 21 | catch( X &xr ) // no diagnostic 22 | {} 23 | catch( X *xp ) // diagnostic 24 | {} 25 | } 26 | -------------------------------------------------------------------------------- /cpp_rules/testEXP09A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP09-A. Treat relational and equality operators as if they were nonassociative 3 | 4 | The relational and equality operators are left-associative, not non-associative as they often are in other languages. This allows a C++ programmer to write an expression (particularly an expression used as a condition) that can be easily misinterpreted. 5 | */ 6 | 7 | void f() { // diagnostic 8 | int a = 2; 9 | int b = 2; 10 | int c = 2; 11 | // ... 12 | if ( a < b < c ) // condition #1, misleading, likely bug 13 | ; 14 | if ( a == b == c ) // condition #2, misleading, likely bug 15 | ; 16 | } 17 | 18 | void g() { // no diagnostic 19 | int a = 2; 20 | int b = 2; 21 | int c = 2; 22 | if ( a < b && b < c ) // clearer, and probably what was intended 23 | ; 24 | if ( a == b && a == c ) // ditto 25 | ; 26 | } 27 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce.ans: -------------------------------------------------------------------------------- 1 | 2 | ENV_CS.c:164: warning: ENV04-C: Do not use system() or popen() unless you need a command interpreter 3 | EXP_CS.c:269: warning: EXP12-C: Do not ignore values returned by functions 4 | FIO_CS.c:712: warning: INT07-C: Use only explicitly signed or unsigned char type for numeric values 5 | FIO_CS.c:865: warning: ENV04-C: Do not use system() or popen() unless you need a command interpreter 6 | INT_CS.c:372: error: INT34-C: Do not shift a negative number of bits or more bits than exist in the operand 7 | MEM_CS.c:77: error: MEM30-C: Do not access freed memory 8 | MSC_CS.c:165: warning: INT07-C: Use only explicitly signed or unsigned char type for numeric values 9 | POS_CS.c:85: error: MEM30-C: Do not access freed memory 10 | STR_CS.c:62: error: STR31-C: String copy destination must contain sufficient storage 11 | STR_CS.c:222: warning: INT01-C: Use rsize_t or size_t for all integer values representing the size of an object 12 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.ARR.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.ARR.c:146: warning: EXP05-C: Do not cast away a const qualification 2 | "./test/c.ncce.wiki.ARR.c", line 245: warning: subscript out of range 3 | for (ip = &ar[0]; ip < &ar[21]; ip++) { 4 | ^ 5 | 6 | c.ncce.wiki.ARR.c:83: warning: EXP01-C: Do not take the sizeof a pointer to determine the sizeof a type 7 | c.ncce.wiki.ARR.c:83: error: EXP34-C: Ensure pointer is valid before dereferencing it 8 | c.ncce.wiki.ARR.c:96: error: EXP36-C: Do not convert pointers into more strictly aligned pointer types 9 | c.ncce.wiki.ARR.c:96: warning: EXP01-C: Do not take the sizeof a pointer to determine the sizeof a type 10 | c.ncce.wiki.ARR.c:96: warning: MEM07-C: Ensure that the arguments to calloc() when multiplied can be represented as a size_t 11 | c.ncce.wiki.ARR.c:117: warning: INT01-C: Use rsize_t or size_t for all integer values representing the size of an object 12 | c.ncce.wiki.ARR.c:208: warning: EXP05-C: Do not cast away a const qualification 13 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.SIG.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.SIG.c:74: error: SIG34-C: Do not call signal() from within interruptible signal handlers 2 | c.ncce.wiki.SIG.c:96: error: SIG30-C: Call only asynchronous-safe functions within signal handlers: free 3 | c.ncce.wiki.SIG.c:96: error: SIG31-C: Do not access or modify shared objects in a signal handler 4 | c.ncce.wiki.SIG.c:123: error: SIG30-C: Call only asynchronous-safe functions within signal handlers: strcpy 5 | c.ncce.wiki.SIG.c:123: error: SIG31-C: Do not access or modify shared objects in a signal handler 6 | c.ncce.wiki.SIG.c:147: error: SIG30-C: Call only asynchronous-safe functions within signal handlers: longjmp 7 | c.ncce.wiki.SIG.c:144: error: SIG31-C: Do not access or modify shared objects in a signal handler 8 | c.ncce.wiki.SIG.c:147: error: SIG32-C: Do not call longjmp() from within a signal handler 9 | c.ncce.wiki.SIG.c:211: error: SIG33-C: Do not recursively invoke the raise() function 10 | c.ncce.wiki.SIG.c:221: error: SIG34-C: Do not call signal() from within interruptible signal handlers 11 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.MSC.ans: -------------------------------------------------------------------------------- 1 | "./test/c.ncce.wiki.MSC.c", line 107: warning: expression has no effect 2 | a == b; 3 | ^ 4 | 5 | "./test/c.ncce.wiki.MSC.c", line 122: warning: nested comment is not allowed 6 | /* some other comment */ 7 | ^ 8 | 9 | "./test/c.ncce.wiki.MSC.c", line 172: warning: statement is unreachable 10 | if (s) { 11 | ^ 12 | 13 | "./test/c.ncce.wiki.MSC.c", line 200: warning: expression has no effect 14 | a == b; 15 | ^ 16 | 17 | c.ncce.wiki.MSC.c:71: warning: MSC01-C: Strive for logical completeness 18 | c.ncce.wiki.MSC.c:107: warning: MSC03-C: Avoid errors of addition 19 | c.ncce.wiki.MSC.c:135: warning: MSC05-C: Do not manipulate time_t typed values directly 20 | c.ncce.wiki.MSC.c:135: warning: MSC05-C: Do not manipulate time_t typed values directly 21 | c.ncce.wiki.MSC.c:200: warning: MSC03-C: Avoid errors of addition 22 | c.ncce.wiki.MSC.c:276: error: MSC30-C: Do not use rand() 23 | c.ncce.wiki.MSC.c:286: error: MSC31-C: Ensure that return values are compared against the proper type 24 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.FLP.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.FLP.c:68: warning: FLP02-C: Consider avoiding floating point numbers when precise computation is needed 2 | c.ncce.wiki.FLP.c:95: error: FLP30-C: Do not use floating point variables as loop counters 3 | c.ncce.wiki.FLP.c:99: error: FLP30-C: Do not use floating point variables as loop counters 4 | c.ncce.wiki.FLP.c:136: error: FLP33-C: Convert integers to floating point for floating point operations 5 | c.ncce.wiki.FLP.c:137: error: FLP33-C: Convert integers to floating point for floating point operations 6 | c.ncce.wiki.FLP.c:138: error: FLP33-C: Convert integers to floating point for floating point operations 7 | c.ncce.wiki.FLP.c:147: error: FLP34-C: Ensure that floating point conversions are within range of the new type 8 | c.ncce.wiki.FLP.c:161: error: FLP34-C: Ensure that floating point conversions are within range of the new type 9 | c.ncce.wiki.FLP.c:162: error: FLP34-C: Ensure that floating point conversions are within range of the new type 10 | c.ncce.wiki.FLP.c:163: error: FLP34-C: Ensure that floating point conversions are within range of the new type 11 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ04A.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ04-A. Prefer not to give virtual functions default argument initializers 3 | 4 | Giving virtual functions default argument initializers tends to defeat polymorphism and introduce unnecessary complexity into a class hierarchy. 5 | */ 6 | 7 | class Thing { 8 | public: 9 | virtual ~Thing(); 10 | virtual void doItNTimes( int numTimes = 10 ); // diagnostic 11 | virtual void doItThisHigh( double howHigh = 1.0 ); // diagnostic 12 | // ... 13 | }; 14 | class MyThing : public Thing { 15 | public: 16 | void doItNTimes( int numTimes ); 17 | void doItThisHigh( double howHigh = 2.2 ); // diagnostic 18 | // ... 19 | }; 20 | 21 | static double const minimumHeight = 1.0; 22 | // ... 23 | namespace XYZ { 24 | class Thing { 25 | public: 26 | virtual ~Thing(); 27 | virtual void doItThisHigh( double howHigh = minimumHeight ); // diagnostic 28 | // ... 29 | }; 30 | } 31 | // ... 32 | namespace XYZ { 33 | static double const minimumHeight = 2.2; 34 | class MyThing : public Thing { 35 | public: 36 | void doItThisHigh( double howHigh = minimumHeight ); // diagnostic 37 | // ... 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ32C.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ32-C. Ensure that single-argument constructors are marked "explicit" 3 | 4 | A single-argument constructor may be used as an implicit conversion function, unless it is marked "explicit" (see [ISO/IEC 14882-2003] Section 12.3.1, "Conversion by constructor"). Such implicit conversions may be unexpected, and lead to undesirable behavior. 5 | */ 6 | 7 | class Widget1 { 8 | public: 9 | Widget1(int size); // diagnostic 10 | //... 11 | }; 12 | 13 | class Widget2 { 14 | public: 15 | explicit Widget2(int size); // no diagnostic 16 | //... 17 | }; 18 | 19 | class Widget3 { 20 | public: 21 | Widget3(int size, int size2 = 10 ); // diagnostic 22 | //... 23 | }; 24 | 25 | class Widget4 { 26 | public: 27 | explicit Widget4(int size, int size2 = 10 ); // no diagnostic 28 | //... 29 | }; 30 | 31 | class Widget5 { 32 | public: 33 | Widget5(int size = 0, int size2 = 10 ); // diagnostic 34 | //... 35 | }; 36 | 37 | class Widget6 { 38 | public: 39 | explicit Widget6(int size = 0, int size2 = 10 ); // no diagnostic 40 | //... 41 | }; 42 | 43 | class Widget7 { 44 | public: 45 | Widget7(); 46 | Widget7( const Widget7 & ); // no diagnostic 47 | //... 48 | }; 49 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.ENV.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.ENV.c:49: warning: ENV00-C: Do not store the pointer to the string returned by getenv() 2 | c.ncce.wiki.ENV.c:69: error: STR31-C: String copy destination must contain sufficient storage 3 | c.ncce.wiki.ENV.c:80: warning: ENV02-C: Beware of multiple environment variables with the same effective name 4 | c.ncce.wiki.ENV.c:67: warning: ENV02-C: Previous reference was here 5 | c.ncce.wiki.ENV.c:119: warning: ENV04-C: Do not use system() or popen() unless you need a command interpreter 6 | c.ncce.wiki.ENV.c:128: error: ENV30-C: Do not modify the string returned by getenv() 7 | c.ncce.wiki.ENV.c:138: error: ENV31-C: Do not rely on an environment pointer following an operation that may invalidate it 8 | c.ncce.wiki.ENV.c:139: error: ENV31-C: Do not rely on an environment pointer following an operation that may invalidate it 9 | c.ncce.wiki.ENV.c:140: error: ENV31-C: Do not rely on an environment pointer following an operation that may invalidate it 10 | c.ncce.wiki.ENV.c:153: error: ENV32-C: No atexit handler should terminate in any way other than by returning 11 | c.ncce.wiki.ENV.c:178: error: ENV32-C: No atexit handler should terminate in any way other than by returning 12 | -------------------------------------------------------------------------------- /cpp_rules/testDCL32C.C: -------------------------------------------------------------------------------- 1 | /* 2 | DCL32-C. Avoid runtime static initialization of objects with external linkage 3 | 4 | Runtime static initializations of namespace scope objects take place before main is entered. The initialization order is well-defined within a particular translation unit, but undefined between translation units. This can give rise to subtle initialization order dependencies and transient, difficult-to-reproduce bugs. There is a similar problem with runtime static destruction, which occurs after return from main. 5 | */ 6 | 7 | extern char const *myGetenv( char const * ); 8 | extern int myStrcmp( char const *, char const * ); 9 | 10 | extern char const *const term; 11 | bool isVT100 = myStrcmp( term, "VT100" ) == 0; // diagnostic 12 | 13 | char const * const term = myGetenv( "TERM" ); // diagnostic 14 | 15 | extern char const *termF(); 16 | 17 | bool isVT100F() { 18 | static bool is = myStrcmp( termF(), "VT100" ) == 0; // no diagnostic 19 | return is; 20 | } 21 | 22 | char const *termF() { 23 | static char const * const theTerm = myGetenv( "TERM" ); // no diagnostic 24 | return theTerm; 25 | } 26 | 27 | static char const * const termL = myGetenv( "TERM" ); // no diagnostic 28 | 29 | static bool isVT100L = myStrcmp( termL, "VT100" ) == 0; // no diagnostic 30 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.FLP.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void FLP30() { 17 | for (float x = 0.1f; x <= 1.0f;) { 18 | x += 0.1f; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cpp_rules/testERR02A.C: -------------------------------------------------------------------------------- 1 | /* 2 | ERR02-A. Throw anonymous temporaries and catch by reference 3 | 4 | When an exception is thrown, the value of the object in the throw expression is used to initialize an anonymous temporary exception object that is in a "safe" location. It is this temporary object that is matched to the types declared in catch clauses and rethrown as the result of a throw; statement. In a way similar to initializing the formal argument of a function with the corresponding actual argument in a function call, the variable in a catch clause is initialized with the anonymous temporary exception object. These mechanics imply the advice given in the title of this recommendation. 5 | */ 6 | 7 | #include 8 | 9 | struct StackUnderflow { 10 | void modify() {} 11 | }; 12 | 13 | extern int h(); 14 | 15 | void f() { 16 | switch( h() ) { 17 | case 1: 18 | throw new StackUnderflow; // diagnostic 19 | case 2: { 20 | StackUnderflow su1; 21 | throw &su1; //diagnostic 22 | } 23 | case 3: { 24 | static StackUnderflow su2; // diagnostic 25 | throw &su2; 26 | } 27 | } 28 | } 29 | 30 | void g() { 31 | try { 32 | f(); 33 | } 34 | catch( StackUnderflow su ) { // diagnostic 35 | su.modify(); // modify argument 36 | throw; // modifications lost 37 | } 38 | catch( std::exception e ) { // diagnostic 39 | throw e; // original type of exception lost 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.ARR.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void clear(int a[], size_t len) { 17 | memset(a, 0, len * sizeof(int)); 18 | } 19 | 20 | void ARR01(void) { 21 | int dis[12]; 22 | 23 | clear(dis, sizeof(dis) / sizeof(dis[0])); 24 | } 25 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.ARR.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | #define ARR_LEN 10 17 | 18 | void clear3(int a[ARR_LEN]) { 19 | memset(a, 0, sizeof(a)); /* error */ 20 | } 21 | 22 | void ARR01(void) { 23 | int b[ARR_LEN]; 24 | clear3(b); 25 | /* ... */ 26 | } 27 | -------------------------------------------------------------------------------- /cpp_rules/testEXP08A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP08-A. A switch statement should have a default clause unless every enumeration value is tested 3 | Added by Fred Long, last edited by Justin Pincar on Sep 12, 2007 (view change) show comment hide comment 4 | Comment: Edited by sciSpider (sch jbop) (X_X)@==(Q_Q)@ 5 | View page history 6 | Labels: 7 | (None) 8 | 9 | 10 | Add Labels 11 | 12 | Wait Image 13 | Enter labels to add to this page: 14 | Tip: Looking for a label? Just start typing. 15 | 16 | 17 | If there is no default clause in a switch statement, then the compiler can issue a warning when not all of the enumeration values are tested. So, the lack of a default clause should indicate that every enumeration value is tested. If all values are not tested, then a default clause should be included for completeness (see [MSC01-A. Strive for Logical Completeness]). 18 | */ 19 | 20 | enum WidgetEnum { WE_W, WE_X, WE_Y, WE_Z }; 21 | 22 | void f( WidgetEnum widget_type ) { 23 | switch (widget_type) { // diagnostic 24 | case WE_X: 25 | break; 26 | case WE_Y: 27 | break; 28 | case WE_Z: 29 | break; 30 | } 31 | 32 | switch (widget_type) { // no diagnostic 33 | case WE_X: 34 | break; 35 | case WE_Y: 36 | case WE_W: 37 | break; 38 | case WE_Z: 39 | break; 40 | } 41 | 42 | switch (widget_type) { // no diagnostic 43 | default: 44 | case WE_X: 45 | break; 46 | case WE_Y: 47 | break; 48 | case WE_Z: 49 | break; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.INT.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void INT09(void) { 17 | enum { red=4, orange, yellow, green, blue, indigo, violet=7 }; 18 | } 19 | 20 | void INT33(void) { 21 | signed long sl1 = 0; 22 | signed long sl2 = 0; 23 | sl1 /= sl2; 24 | sl2 %= sl1; 25 | } 26 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.MSC.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void MSC03() { 17 | unsigned int a = 0; 18 | const unsigned int b = 0; 19 | 20 | while (b == 4); { 21 | /* Do while b == 4 */ 22 | } 23 | 24 | for (a=5; a < 10; a++); { 25 | /* Do while a < 10 */ 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ02A.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ02-A. Do not hide inherited non-virtual member functions 3 | 4 | Conventionally, a non-virtual member function specifies an invariant over the hierarchy. It cannot be overridden in derived classes, but it can be hidden by a derived class member (data or function) with the same identifier. The effect of this hiding is to defeat polymorphism by causing an object to behave differently depending on which interface is used to manipulate it, resulting in unnecessary complexity and error. 5 | */ 6 | 7 | struct Point { 8 | int x_; 9 | int y_; 10 | }; 11 | 12 | class Target { 13 | public: 14 | Target(); 15 | virtual ~Target(); 16 | Point extent() const; 17 | Point position() const 18 | { return center_; } 19 | // ... 20 | Target( const Target & ); 21 | Target &operator =( const Target & ); 22 | void operator =( int ); 23 | private: 24 | Point center_; 25 | }; 26 | class SquareTarget : public Target { 27 | public: 28 | SquareTarget(); 29 | Point position() const // diagnostic: improper hiding of non-virtual 30 | { return upperLeft_; } 31 | // ... 32 | SquareTarget( const SquareTarget & ); 33 | SquareTarget &operator =( const SquareTarget & ); // no diagnostic: copy operator = not inherited 34 | void operator =( int ); // diagnostic: not a copy assign 35 | private: 36 | Point upperLeft_; 37 | }; 38 | 39 | void f() { 40 | SquareTarget target; 41 | } 42 | -------------------------------------------------------------------------------- /rosecheckers/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include 15 | 16 | /** Returns an array of doubles */ 17 | double *allocate_array() { 18 | double *d_array; 19 | size_t num_elems = 10; 20 | d_array = (double*) malloc(sizeof(d_array) * num_elems); 21 | return d_array; // (d_array == NULL) ? NULL : d_array; 22 | } 23 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.MSC.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | /* MSC03_A v.26 */ 17 | 18 | void MSC03() { 19 | unsigned int a = 0; 20 | const unsigned int b = 0; 21 | 22 | while (b == 4) { 23 | /* Do while b == 4 */ 24 | } 25 | 26 | for (a=5; a < 10; a++) { 27 | /* Do while a < 10 */ 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/value.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file value.h 3 | * 4 | * Copyright (c) 2007 Carnegie Mellon University. 5 | * All rights reserved. 6 | 7 | * Permission to use this software and its documentation for any purpose is 8 | * hereby granted, provided that the above copyright notice appear and that 9 | * both that copyright notice and this permission notice appear in supporting 10 | * documentation, and that the name of CMU not be used in advertising or 11 | * publicity pertaining to distribution of the software without specific, 12 | * written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 15 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 16 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 19 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef VALUE_H 24 | #define VALUE_H 25 | 26 | #include "rose.h" 27 | 28 | bool getSizetVal(const SgExpression *node, size_t *value); 29 | bool getIntegerVal(const SgExpression *node, intmax_t *n); 30 | bool getFloatingVal(const SgExpression *node, long double *n); 31 | bool isVal(const SgExpression *node, const intmax_t n); 32 | bool isZeroVal(const SgExpression *node); 33 | bool isMinVal(const SgExpression *node); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /cpp_rules/FLP.C: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2007 Carnegie Mellon University. 4 | * All rights reserved. 5 | 6 | * Permission to use this software and its documentation for any purpose is hereby granted, 7 | * provided that the above copyright notice appear and that both that copyright notice and 8 | * this permission notice appear in supporting documentation, and that the name of CMU not 9 | * be used in advertising or publicity pertaining to distribution of the software without 10 | * specific, written prior permission. 11 | * 12 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 13 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 14 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 15 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 16 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "rose.h" 22 | 23 | bool FLP31_C( const SgNode *node ) { // Do not use floating point variables as loop counters 24 | return false; 25 | } 26 | 27 | bool FLP( SgProject *project ) { 28 | bool violation = false; 29 | Rose_STL_Container nodes = NodeQuery::querySubTree( project, V_SgNode ); //XXX should use visit 30 | for( Rose_STL_Container::iterator i = nodes.begin(); i != nodes.end(); ++i ) { 31 | violation |= FLP31_C( *i ); 32 | } 33 | return violation; 34 | } 35 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/example.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file example.c 3 | * 4 | * \brief This program serves to demonstrate CERT/CC's secure coding rules, in 5 | * conjunction with flymake. It compiles with no warnings from gcc, but Rose 6 | * has some extra information... 7 | * 8 | * Copyright (c) 2007 Carnegie Mellon University. 9 | * All rights reserved. 10 | 11 | * Permission to use this software and its documentation for any purpose is 12 | * hereby granted, provided that the above copyright notice appear and that 13 | * both that copyright notice and this permission notice appear in supporting 14 | * documentation, and that the name of CMU not be used in advertising or 15 | * publicity pertaining to distribution of the software without specific, 16 | * written prior permission. 17 | * 18 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 19 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 20 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 22 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 23 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 | * 25 | */ 26 | 27 | #include 28 | 29 | /** Returns an array of doubles */ 30 | double *allocate_array() { 31 | double *d_array; 32 | size_t num_elems = 10; 33 | d_array = (double*) malloc(sizeof(d_array) * num_elems); 34 | return d_array; // (d_array == NULL) ? NULL : d_array; 35 | } 36 | -------------------------------------------------------------------------------- /cpp_rules/testOBJ00A.C: -------------------------------------------------------------------------------- 1 | /* 2 | OBJ00-A. Declare data members private 3 | 4 | If data members are declared public or protected, it is difficult to control how they are accessed. It is possible that they could be manipulated in unintented ways, with undefined consequences. Better is to declare all data members private and define accessor functions that control their uses to those intended. Also, modification of data members can be monitored as appropriate (e.g., by logging). Public modifier functions should preserve any invariants of the type. 5 | */ 6 | 7 | typedef int someType; 8 | 9 | class Widget { 10 | public: 11 | int total; // diagnostic 12 | // ... 13 | Widget (): total(0) {} 14 | // ... 15 | void add (someType someParameters) { 16 | // ... 17 | total++; 18 | // ... 19 | } 20 | void remove (someType someParameters) { 21 | // ... 22 | total--; 23 | // ... 24 | } 25 | // ... 26 | }; 27 | 28 | class Widget2 { 29 | public: 30 | Widget2 (): total(0) {} 31 | // ... 32 | void add (someType someParameters) { 33 | // ... 34 | total++; 35 | // ... 36 | } 37 | void remove (someType someParameters) { 38 | // ... 39 | total--; 40 | // ... 41 | } 42 | // ... 43 | int getTotal () {return total;} 44 | // ... 45 | private: 46 | int total; // no diagnostic 47 | // ... 48 | }; 49 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.DCL.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void DCL02_1(void) { 17 | const int home1 = 6; 18 | const int nome2 = 4; 19 | if (nome2 == home1) { 20 | printf("We found home1 to be wrong"); 21 | } 22 | } 23 | 24 | void DCL02_2(void) { 25 | const int home1 = 6; 26 | const int horne2 = 4; 27 | if (horne2 == home1) { 28 | printf("We found home1 to be wrong"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.MEM.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.MEM.c:95: warning: MEM01-C: Store a new value in pointers immediately after free() 2 | c.ncce.wiki.MEM.c:95: error: MEM30-C: Do not access freed memory 3 | c.ncce.wiki.MEM.c:95: error: MEM31-C: Free dynamically allocated memory exactly once. 4 | c.ncce.wiki.MEM.c:101: warning: MEM01-C: Store a new value in pointers immediately after free() 5 | c.ncce.wiki.MEM.c:148: warning: MEM04-C: Do not perform zero length allocations 6 | c.ncce.wiki.MEM.c:166: warning: MEM04-C: Do not perform zero length allocations 7 | c.ncce.wiki.MEM.c:224: warning: MEM07-C: Ensure that the arguments to calloc() when multiplied can be represented as a size_t 8 | c.ncce.wiki.MEM.c:254: warning: MEM08-C: Use realloc() only to resize dynamically allocated arrays 9 | c.ncce.wiki.MEM.c:296: error: MEM30-C: Do not access freed memory 10 | c.ncce.wiki.MEM.c:296: error: MEM34-C: Only free memory allocated dynamically 11 | c.ncce.wiki.MEM.c:307: warning: MEM01-C: Store a new value in pointers immediately after free() 12 | c.ncce.wiki.MEM.c:307: error: MEM30-C: Do not access freed memory 13 | c.ncce.wiki.MEM.c:329: warning: MEM01-C: Store a new value in pointers immediately after free() 14 | c.ncce.wiki.MEM.c:329: error: MEM30-C: Do not access freed memory 15 | c.ncce.wiki.MEM.c:329: error: MEM31-C: Free dynamically allocated memory exactly once. 16 | c.ncce.wiki.MEM.c:344: error: EXP34-C: Ensure pointer is valid before dereferencing it 17 | c.ncce.wiki.MEM.c:363: error: MEM33-C: Use the correct syntax for flexible array members 18 | c.ncce.wiki.MEM.c:413: error: MEM34-C: Only free memory allocated dynamically 19 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.POS.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | int POS34_1(){ 17 | const char environment[] = "bob the sponge"; 18 | return putenv((char*) environment); // const must be cast away 19 | } 20 | 21 | int POS34_2(char* var) { 22 | char environment[1024]; 23 | 24 | if (snprintf(environment, sizeof(environment),"TEST=%s", var) < 0) { 25 | /* Handle Error */ 26 | } 27 | char* env2 = &environment[0]; 28 | 29 | return putenv(env2); 30 | } 31 | -------------------------------------------------------------------------------- /cpp_rules/testEXP36C.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP36-C. Do not cast or delete pointers to incomplete classes 3 | 4 | The use of incomplete class declarations (also known as "forward" declarations) is common. While it is possible to declare pointers and references to incomplete classes, because the class definition is not available it is not possible to access a member of the class, determine the size of the class object, and so on. However, it is possible to cast and delete a pointer to an incomplete class, but this is never a good idea. 5 | */ 6 | /* 7 | class Body; // incomplete class declaration 8 | 9 | class Handle { 10 | public: 11 | Handle(); 12 | ~Handle() 13 | { delete impl_; } // diagnostic: deletion of pointer to incomplete class 14 | private: 15 | Handle( const Handle & ); 16 | Handle &operator =( const Handle & ); 17 | Body *impl_; 18 | }; 19 | 20 | class B { 21 | }; 22 | B *getMeSomeSortOfB(); 23 | 24 | class D; // incomplete declaration 25 | 26 | void f() { 27 | B *bp = getMeSomeSortOfB(); 28 | D *dp = (D *)bp; // diagnostic: old-stlye cast: legal, but inadvisable 29 | dp = reinterpret_cast(bp); // diagnostic: new-style cast: legal, but inadvisable 30 | delete bp; // no diagnostic 31 | delete dp; // diagnostic 32 | } 33 | */ 34 | class C; 35 | inline void g( C *cp ) { 36 | delete cp; // diagnostic 37 | } 38 | 39 | class C {}; 40 | inline void h( C *cp ) { 41 | delete cp; // no diagnostic 42 | } 43 | /* 44 | class E { 45 | public: 46 | void mf1( E *dp ) { 47 | delete dp; // no diagnostic 48 | } 49 | void mf2(); 50 | }; 51 | void E::mf2() { 52 | delete this; // no diagnostic 53 | } 54 | */ 55 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/PRE.C: -------------------------------------------------------------------------------- 1 | /** 2 | * \file PRE.C 3 | * 4 | * \note As written, these tests catch template declarations only if 5 | * instantiated. 6 | * 7 | * Copyright (c) 2007 Carnegie Mellon University. 8 | * All rights reserved. 9 | 10 | * Permission to use this software and its documentation for any purpose is 11 | * hereby granted, provided that the above copyright notice appear and that 12 | * both that copyright notice and this permission notice appear in supporting 13 | * documentation, and that the name of CMU not be used in advertising or 14 | * publicity pertaining to distribution of the software without specific, 15 | * written prior permission. 16 | * 17 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 18 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 19 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 21 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 22 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23 | */ 24 | 25 | #include "rose.h" 26 | #include "utilities.h" 27 | 28 | /** 29 | * Do not reuse a standard header file name 30 | * 31 | * \bug BROKEN, NEEDS ROSE SUPPPORT 32 | */ 33 | //bool PRE04_C( const SgNode *node ) { 34 | // return false; 35 | //} 36 | 37 | /** 38 | * \note we have to call this PREPRO because of a namespace clash with PRE 39 | */ 40 | bool PREPRO(const SgNode *node) { 41 | bool violation = false; 42 | // violation |= PRE04_C(node); 43 | return violation; 44 | } 45 | -------------------------------------------------------------------------------- /rosecheckers/value.h: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | /** 15 | * \file value.h 16 | */ 17 | 18 | #ifndef VALUE_H 19 | #define VALUE_H 20 | 21 | #include "rose.h" 22 | 23 | bool getSizetVal(const SgExpression *node, size_t *value); 24 | bool getIntegerVal(const SgExpression *node, intmax_t *n); 25 | bool getFloatingVal(const SgExpression *node, long double *n); 26 | bool isVal(const SgExpression *node, const intmax_t n); 27 | bool isZeroVal(const SgExpression *node); 28 | bool isMinVal(const SgExpression *node); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.INT.ans: -------------------------------------------------------------------------------- 1 | "./test/c.ncce.wiki.INT.c", line 132: warning: integer conversion resulted in a change of sign 2 | const char c = 200; 3 | ^ 4 | 5 | c.ncce.wiki.INT.c:91: error: INT33-C: Ensure that division and modulo operations do not result in divide-by-zero errors 6 | c.ncce.wiki.INT.c:115: warning: INT05-C: Do not use input functions to convert character data if they cannot handle all possible inputs 7 | c.ncce.wiki.INT.c:123: warning: INT01-C: Use strtol() or a related function to convert a string token to an integer 8 | c.ncce.wiki.INT.c:132: warning: INT07-C: Use only explicitly signed or unsigned char type for numeric values 9 | c.ncce.wiki.INT.c:149: warning: INT09-C: Ensure enumeration constants map to unique values 10 | c.ncce.wiki.INT.c:181: warning: EXP11-C: Do not apply operators expecting one type to data of an incompatible type 11 | c.ncce.wiki.INT.c:181: warning: INT11-C: Take care when converting from pointer to integer or integer to pointer 12 | c.ncce.wiki.INT.c:188: warning: INT12-C: Do not make assumptions about the type of a plain int bit-field when used in an expression 13 | c.ncce.wiki.INT.c:213: warning: INT14-C: Avoid performing bitwise and arithmetic operations on the same data 14 | c.ncce.wiki.INT.c:246: error: INT32-C: Ensure that operations on signed integers do not result in overflow 15 | c.ncce.wiki.INT.c:259: error: INT33-C: Ensure that division and modulo operations do not result in divide-by-zero errors 16 | c.ncce.wiki.INT.c:269: warning: INT13-C: Use bitwise operators only on unsigned operands 17 | c.ncce.wiki.INT.c:269: error: INT34-C: Do not shift a negative number of bits or more bits than exist in the operand 18 | -------------------------------------------------------------------------------- /rosecheckers/gcc_as_rosecheckers: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # To use this script, rename it to 'gcc' and put it in your $PATH ahead of /usr/bin/gcc 4 | 5 | # 6 | # CERT Rosecheckers 7 | # Copyright 2022 Carnegie Mellon University. 8 | # NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 9 | # Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 10 | # [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 11 | # CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 12 | # This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 13 | # DM21-0505 14 | # 15 | 16 | ARGS=$* 17 | CLANG_ARGS=`echo $ARGS | perl -p -e 's/-fmacro-prefix-map=[^ ]*//g;'` 18 | PROCESSED_ARGS=`echo $CLANG_ARGS | perl -p -e 's/-MT .*?\.lo//g; s/-o .*?\.[do]\s/ /g; s/-MM //g; s/-x [^ ]* / /g;'` 19 | REAL_SRC=`echo $ARGS | perl -p -e 's/(.*) ([^ ]*)\.c(.*|$)/\2/;'` 20 | echo "In directory: " `pwd` 21 | echo "Compiler args are: " $ARGS 22 | /usr/bin//rosecheckers $PROCESSED_ARGS 23 | /usr/bin/gcc $ARGS 24 | -------------------------------------------------------------------------------- /cpp_rules/diagnose.C: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2007 Carnegie Mellon University. 4 | * All rights reserved. 5 | 6 | * Permission to use this software and its documentation for any purpose is hereby granted, 7 | * provided that the above copyright notice appear and that both that copyright notice and 8 | * this permission notice appear in supporting documentation, and that the name of CMU not 9 | * be used in advertising or publicity pertaining to distribution of the software without 10 | * specific, written prior permission. 11 | * 12 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 13 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 14 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 15 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 16 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "rose.h" 23 | #include "utilities.h" 24 | 25 | extern bool EXP( SgProject *project ); 26 | extern bool OBJ( SgProject *project ); 27 | extern bool DCL( SgProject *project ); 28 | extern bool ERR( SgProject *project ); 29 | extern bool FLP( SgProject *project ); 30 | extern bool RES( SgProject *project ); 31 | 32 | int main( int argc, char * argv[] ) { 33 | SgProject* project = frontend( argc, argv ); 34 | ROSE_ASSERT( project ); 35 | AstTests::runAllTests( project ); 36 | 37 | EXP( project ); 38 | OBJ( project ); 39 | DCL( project ); 40 | ERR( project ); 41 | FLP( project ); 42 | RES( project ); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.DCL.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void DCL01_1(void) { 17 | int tmp=1; 18 | while(1) { 19 | int tmp=0; 20 | /* use tmp */ 21 | printf("tmp=%d\n", tmp); 22 | } 23 | } 24 | 25 | void DCL02_1(void) { 26 | const int notel = 6; 27 | const int note1 = 4; 28 | if (notel == note1) { 29 | printf("We found notel to be wrong"); 30 | } 31 | } 32 | 33 | void DCL02_2(void) { 34 | const int home = 6; 35 | const int nome = 4; 36 | if (home == nome) { 37 | printf("We found home to be wrong"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rosecheckers/g++_as_rosecheckers: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # To use this script, rename it to 'g++' and put it in your $PATH ahead of /usr/bin/g++ 4 | 5 | # 6 | # CERT Rosecheckers 7 | # Copyright 2022 Carnegie Mellon University. 8 | # NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 9 | # Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 10 | # [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 11 | # CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 12 | # This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 13 | # DM21-0505 14 | # 15 | 16 | 17 | ARGS=$* 18 | CLANG_ARGS=`echo $ARGS | perl -p -e 's/-fmacro-prefix-map=[^ ]*//g;'` 19 | PROCESSED_ARGS=`echo $CLANG_ARGS | perl -p -e 's/-MT .*?\.lo//g; s/-o .*?\.[do]\s/ /g; s/-MM //g; s/-x [^ ]* / /g;'` 20 | PROCESSED_ARGS=`echo $CLANG_ARGS | perl -p -e 's/-MT .*?\.lo//g; s/-o .*?\.[do]\s/ /g; s/-MM //g; s/-x [^ ]* / /g;'` 21 | REAL_SRC=`echo $ARGS | perl -p -e 's/(.*) ([^ ]*)\.c(.*|$)/\2/;'` 22 | echo "In directory: " `pwd` 23 | echo "Compiler args are: " $ARGS 24 | /usr/bin/rosecheckers $ARGS 25 | /usr/bin/g++ $ARGS 26 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.STR.ans: -------------------------------------------------------------------------------- 1 | "./test/c.ncce.wiki.STR.c", line 67: warning: argument of type "signed char *" is incompatible with parameter of type "const char *" 2 | len = strlen(scstr); /* warns when char is unsigned */ 3 | ^ 4 | 5 | "./test/c.ncce.wiki.STR.c", line 69: warning: argument of type "unsigned char *" is incompatible with parameter of type "const char *" 6 | len = strlen(ucstr); /* warns when char is signed */ 7 | ^ 8 | 9 | c.ncce.wiki.STR.c:62: warning: ARR02-C: Explicitly specify array dimensions, even if implicitly defined by an initializer 10 | c.ncce.wiki.STR.c:62: warning: STR04-C: Use plain char for characters in the basic character set 11 | c.ncce.wiki.STR.c:63: warning: ARR02-C: Explicitly specify array dimensions, even if implicitly defined by an initializer 12 | c.ncce.wiki.STR.c:63: warning: STR04-C: Use plain char for characters in the basic character set 13 | c.ncce.wiki.STR.c:77: warning: STR05-C: Use pointers to const when referring to string literals 14 | c.ncce.wiki.STR.c:86: error: ENV30-C: Do not modify the string returned by getenv() 15 | c.ncce.wiki.STR.c:94: warning: STR06-C: Do not assume that strtok() leaves the parse string unchanged 16 | c.ncce.wiki.STR.c:102: warning: STR05-C: Use pointers to const when referring to string literals 17 | c.ncce.wiki.STR.c:103: error: STR30-C: Do not attempt to modify string literals 18 | c.ncce.wiki.STR.c:131: error: STR32-C: Null-terminate byte strings as required 19 | c.ncce.wiki.STR.c:170: error: STR35-C: Do not copy data from an unbounded source to a fixed-length array 20 | c.ncce.wiki.STR.c:179: error: STR36-C: Do not specify the dimension of a character array initialized with a string literal 21 | c.ncce.wiki.STR.c:190: warning: INT01-C: Use rsize_t or size_t for all integer values representing the size of an object 22 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/categories.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file categories.h 3 | * 4 | * Copyright (c) 2007 Carnegie Mellon University. 5 | * All rights reserved. 6 | 7 | * Permission to use this software and its documentation for any purpose is 8 | * hereby granted, provided that the above copyright notice appear and that 9 | * both that copyright notice and this permission notice appear in supporting 10 | * documentation, and that the name of CMU not be used in advertising or 11 | * publicity pertaining to distribution of the software without specific, 12 | * written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 15 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 16 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 19 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef CATEGORIES_H 24 | #define CATEGORIES_H 25 | 26 | #include "rose.h" 27 | #include "utilities.h" 28 | 29 | const SgBinaryOp *isAnyBinArithOp(const SgNode *node); 30 | const SgBinaryOp *isAnyBinArithAssignOp(const SgNode *node); 31 | const SgBinaryOp *isAnyBinBitOp(const SgNode *node); 32 | const SgBinaryOp *isAnyBinBitAssignOp(const SgNode *node); 33 | const SgBinaryOp *isAnyBinLogicOp(const SgNode *node); 34 | const SgBinaryOp *isAnyAssignOp(const SgNode *node); 35 | const SgBinaryOp *isAnyEqualityOp(const SgNode *node); 36 | const SgBinaryOp *isAnyRelationalOp(const SgNode *node); 37 | const SgBinaryOp *isAnyComparisonOp(const SgNode *node); 38 | 39 | bool isAnyCharType(const SgType *type); 40 | bool isAnyPointerType(const SgType *type); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.EXP.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void EXP09_1() { 17 | const char** random2 = (const char**) malloc(4); 18 | int **matrix = (int**) malloc(10*sizeof(int*)); 19 | matrix[0] = (int*)realloc( matrix[0], 10*4); 20 | } 21 | 22 | void EXP09_2() { 23 | size_t i; 24 | int **triarray = (int**) malloc(100 * 4); 25 | 26 | if (!triarray) { 27 | /* handle error */ 28 | } 29 | 30 | for (i = 0; i < 100; i++) { 31 | triarray[i] = (int*) malloc(20 * 4); 32 | if (!triarray[i]) { 33 | /* handle error */ 34 | } 35 | } 36 | } 37 | 38 | void EXP30() { 39 | int i; 40 | for(i = 0; i < 10; i = i++ + 1){ 41 | /* Loop */ 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rosecheckers/PRE.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | /** 15 | * \file PRE.C 16 | */ 17 | 18 | #include "rose.h" 19 | #include "utilities.h" 20 | 21 | /** 22 | * Do not reuse a standard header file name 23 | * 24 | * \bug BROKEN, NEEDS ROSE SUPPPORT 25 | */ 26 | //bool PRE04_C( const SgNode *node ) { 27 | // return false; 28 | //} 29 | 30 | /** 31 | * \note we have to call this PREPRO because of a namespace clash with PRE 32 | */ 33 | bool PRE_C(const SgNode *node) { 34 | bool violation = false; 35 | // violation |= PRE04_C(node); 36 | return violation; 37 | } 38 | 39 | 40 | /// C++ checkers 41 | 42 | bool PRE_CPP(const SgNode *node) { 43 | bool violation = false; 44 | violation |= PRE_C(node); 45 | return violation; 46 | } 47 | -------------------------------------------------------------------------------- /cpp_rules/testRES35C.C: -------------------------------------------------------------------------------- 1 | /* 2 | RES35-C. Declare a copy constructor, a copy assignment operator, and a destructor in a class that manages resources 3 | 4 | A copy constructor, a copy assignment operator, and a destructor are created automatically by the compiler for a class in which they are not provided by the coder. However, in a class that manages resources, the defaults provided by the compiler will usually not be sufficient to ensure that the resources are properly managed (see RES34-C. Encapsulate resources that require paired acquire and release in objects). 5 | 6 | For example, suppose an object contains a string that is implemented as a pointer allocated using new. If a destructor is provided that deletes the pointer, but no copy constructor is provided, it is likely that some pointers will be deleted multiple times. This is because the default copy constructor does memberwise initialization. Hence, the pointer would be copied, not the array of characters. Therefore, we could end up with several copies of the same pointer in different objects, and deleting those objects would result in an attempt to delete the same pointer several times. 7 | */ 8 | 9 | class Widget { 10 | }; 11 | 12 | class Thingy1 { // diagnostic 13 | public: 14 | Thingy1(); 15 | private: 16 | Widget *w; 17 | }; 18 | 19 | class Thingy2 { // no diagnostic 20 | public: 21 | Thingy2(); 22 | Thingy2(const Thingy2 &value); 23 | Thingy2 &operator=(const Thingy2 &rhs); 24 | ~Thingy2(); 25 | // ... 26 | private: 27 | Widget *w; 28 | }; 29 | 30 | Thingy2::Thingy2(const Thingy2 &value) : w( new Widget(*value.w) ) 31 | {} 32 | 33 | Thingy2 &Thingy2::operator=(const Thingy2 &rhs) { 34 | Widget *temp = new Widget(*rhs.w); 35 | delete w; 36 | w = temp; 37 | return *this; 38 | } 39 | 40 | Thingy2::~Thingy2() { 41 | delete w; 42 | } 43 | -------------------------------------------------------------------------------- /rosecheckers/test_next_visitor.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include 15 | 16 | // This routine is strictly for testing the visit_next function; it should 17 | // visit nodes in the order of i = 1, 2, 3 ... 18 | 19 | void foo() { 20 | char* x = NULL; 21 | int i = 0; 22 | while (i == -1) { 23 | i = -2; 24 | } 25 | 26 | for (i = -3; i == -4; i++) { 27 | i = -5; 28 | } 29 | 30 | for (i = -3; i == 5; i++) { 31 | i = 6; 32 | do { 33 | i = 3; 34 | free(x); 35 | i = 1; 36 | } while (i == 2); 37 | i = 4; 38 | } 39 | 40 | while (i == 7) { 41 | i = 8; 42 | if (i == 9) { 43 | i = 10; 44 | return; 45 | } 46 | i == 11; 47 | } 48 | 49 | 50 | for (i = 12; i == 13; i++) { 51 | i = 14; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.FIO.ans: -------------------------------------------------------------------------------- 1 | c.ncce.wiki.FIO.c:109: warning: FIO01-C: Be careful using functions that use file names for identification 2 | c.ncce.wiki.FIO.c:156: warning: EXP12-C: Do not ignore values returned by functions: fseek 3 | c.ncce.wiki.FIO.c:236: error: EXP37-C: Call functions with the arguments intended by the API 4 | c.ncce.wiki.FIO.c:265: warning: FIO07-C: Prefer fseek() to rewind() 5 | c.ncce.wiki.FIO.c:286: warning: FIO08-C: Take care when calling remove() on an open file 6 | c.ncce.wiki.FIO.c:333: warning: FIO12-C: Prefer setvbuf() to setbuf() 7 | c.ncce.wiki.FIO.c:352: warning: FIO13-C: Never push back anything other than one read character 8 | c.ncce.wiki.FIO.c:423: warning: ARR001_C: Do not apply the sizeof operator to an object of pointer 9 | c.ncce.wiki.FIO.c:432: error: FIO30-C: Exclude user input from format strings 10 | c.ncce.wiki.FIO.c:495: warning: EXP12-C: Do not ignore values returned by functions: fgets 11 | c.ncce.wiki.FIO.c:506: warning: INT07-C: Use only explicitly signed or unsigned char type for numeric values 12 | c.ncce.wiki.FIO.c:506: error: FIO34-C: Use int to capture the return value of character I/O functions 13 | c.ncce.wiki.FIO.c:556: error: FIO38-C: Do not use a copy of a FILE object for input and output 14 | c.ncce.wiki.FIO.c:577: error: FIO39-C: Do not alternately input and output from a stream without an intervening flush or positioning call 15 | c.ncce.wiki.FIO.c:625: error: FIO42-C: Ensure files are properly closed when they are no longer needed 16 | c.ncce.wiki.FIO.c:634: warning: ENV04-C: Do not use system() or popen() unless you need a command interpreter 17 | c.ncce.wiki.FIO.c:654: error: FIO43-C: Do not use fopen() on the results of tmpnam() 18 | c.ncce.wiki.FIO.c:680: error: FIO43-C: Do not use open() on the results of mktemp() 19 | c.ncce.wiki.FIO.c:692: error: FIO43-C: Do not use tmpfile() 20 | c.ncce.wiki.FIO.c:712: error: FIO44-C: Only use values for fsetpos() that are returned from fgetpos() 21 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | /* 5 | * Copyright (c) 2007 Carnegie Mellon University. 6 | * All rights reserved. 7 | 8 | * Permission to use this software and its documentation for any purpose is hereby granted, 9 | * provided that the above copyright notice appear and that both that copyright notice and 10 | * this permission notice appear in supporting documentation, and that the name of CMU not 11 | * be used in advertising or publicity pertaining to distribution of the software without 12 | * specific, written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 15 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 16 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 17 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 18 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | extern char **environ; 49 | 50 | /* This is for the case where we just want to run it through a static 51 | * analysis tool and don't care about runtime errors. This is not 52 | * specified as a #define to avoid being ignored by the tools. 53 | */ 54 | #define RUNTIME_IGNORE 1 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | /* 5 | * Copyright (c) 2007 Carnegie Mellon University. 6 | * All rights reserved. 7 | 8 | * Permission to use this software and its documentation for any purpose is hereby granted, 9 | * provided that the above copyright notice appear and that both that copyright notice and 10 | * this permission notice appear in supporting documentation, and that the name of CMU not 11 | * be used in advertising or publicity pertaining to distribution of the software without 12 | * specific, written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 15 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 16 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 17 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 18 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | extern char **environ; 49 | 50 | /* This is for the case where we just want to run it through a static 51 | * analysis tool and don't care about runtime errors. This is not 52 | * specified as a #define to avoid being ignored by the tools. 53 | */ 54 | #define RUNTIME_IGNORE 1 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /rosecheckers/categories.h: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | /** 15 | * \file categories.h 16 | */ 17 | 18 | #ifndef CATEGORIES_H 19 | #define CATEGORIES_H 20 | 21 | #include "rose.h" 22 | #include "utilities.h" 23 | 24 | const SgBinaryOp *isAnyBinArithOp(const SgNode *node); 25 | const SgBinaryOp *isAnyBinArithAssignOp(const SgNode *node); 26 | const SgBinaryOp *isAnyBinBitOp(const SgNode *node); 27 | const SgBinaryOp *isAnyBinBitAssignOp(const SgNode *node); 28 | const SgBinaryOp *isAnyBinLogicOp(const SgNode *node); 29 | const SgBinaryOp *isAnyAssignOp(const SgNode *node); 30 | const SgBinaryOp *isAnyEqualityOp(const SgNode *node); 31 | const SgBinaryOp *isAnyRelationalOp(const SgNode *node); 32 | const SgBinaryOp *isAnyComparisonOp(const SgNode *node); 33 | 34 | bool isAnyCharType(const SgType *type); 35 | bool isAnyPointerType(const SgType *type); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.xtra.MEM.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | #include 16 | 17 | 18 | void MEM31(void) { 19 | typedef struct ll { 20 | struct ll *next; 21 | } ll_t; 22 | 23 | ll_t *head = (ll_t*) malloc(sizeof(ll_t)); // initialize 24 | ll_t *temp; 25 | 26 | //free elements of linked list 27 | while(head != NULL) { 28 | temp=head->next; 29 | free(head); 30 | head=temp; 31 | } 32 | 33 | //error deleting temporary variable 34 | free(temp); 35 | } 36 | 37 | 38 | enum { LEN = 1000 }; 39 | 40 | void MEM34(int argc, char const *argv[]) { 41 | char *str = NULL; 42 | if (argc == 2) { 43 | str = (char *)malloc(LEN); 44 | } 45 | else if(argc == 3){ 46 | str = "usage: $>a.exe [string]"; 47 | } 48 | else{ 49 | str = (char *)malloc(LEN / 2); 50 | } 51 | 52 | if(str == NULL){ 53 | /* Handle error*/ 54 | } 55 | free(str); 56 | } 57 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.EXP.ans: -------------------------------------------------------------------------------- 1 | "./test/c.ncce.wiki.EXP.c", line 283: warning: a value of type "int **" cannot be assigned to an entity of type "volatile int **" 2 | ipp = &ip; /* produces warnings in modern compilers */ 3 | ^ 4 | 5 | "./test/c.ncce.wiki.EXP.c", line 285: warning: a value of type "int **" cannot be assigned to an entity of type "volatile int **" 6 | ipp = (int**) &ip; /* constraint violation */ 7 | ^ 8 | 9 | "./test/c.ncce.wiki.EXP.c", line 347: warning: return value type does not match the function type 10 | return v_pointer; 11 | ^ 12 | 13 | c.ncce.wiki.EXP.c:81: warning: EXP01-C: Do not take the sizeof a pointer to determine the sizeof a type 14 | c.ncce.wiki.EXP.c:121: warning: EXP09-C: malloc called using something other than sizeof() 15 | c.ncce.wiki.EXP.c:156: warning: EXP04-C: Do not perform byte-by-byte comparisons between structures 16 | c.ncce.wiki.EXP.c:170: warning: EXP05-C: Do not cast away a const qualification 17 | c.ncce.wiki.EXP.c:187: warning: EXP06-C: Operands to the sizeof operator should not contain side effects 18 | c.ncce.wiki.EXP.c:205: warning: EXP09-C: malloc called using something other than sizeof() 19 | c.ncce.wiki.EXP.c:211: warning: EXP09-C: malloc called using something other than sizeof() 20 | c.ncce.wiki.EXP.c:242: warning: EXP11-C: Do not apply operators expecting one type to data of an incompatible type 21 | c.ncce.wiki.EXP.c:243: warning: EXP11-C: Do not apply operators expecting one type to data of an incompatible type 22 | c.ncce.wiki.EXP.c:254: warning: EXP12-C: Do not ignore values returned by functions: puts 23 | c.ncce.wiki.EXP.c:261: error: EXP30-C: Do not depend on order of evaluation between sequence points 24 | c.ncce.wiki.EXP.c:320: error: EXP34-C: Ensure pointer is valid before dereferencing it 25 | c.ncce.wiki.EXP.c:322: error: EXP34-C: Ensure pointer is valid before dereferencing it 26 | c.ncce.wiki.EXP.c:347: error: EXP36-C: Do not convert pointers into more strictly aligned pointer types 27 | c.ncce.wiki.EXP.c:364: warning: EXP11-C: Do not apply operators expecting one type to data of an incompatible type 28 | -------------------------------------------------------------------------------- /cpp_rules/testEXP10A.C: -------------------------------------------------------------------------------- 1 | /* 2 | EXP10-A. Prefer the prefix forms of ++ and --. 3 | 4 | The unary ++ and ? operators may be applied in either a prefix or postfix form with somewhat different behavior. However, if the value of the unary expression is not used in an enclosing expression, either form will produce the same result (for the built-in ++ and --), or should produce the same result (for user-defined ++ and --). 5 | 6 | However, for user-defined overloaded ++ and -- operators, it is typically possible to produce a prefix implementation that is more efficient than the corresponding postfix version. For this reason, it is considered good practice in C++ to prefer the prefix forms of these operators when either will do. 7 | */ 8 | 9 | struct Iter { 10 | Iter &operator ++(); 11 | Iter operator ++( int ); 12 | Iter &operator --(); 13 | Iter operator --( int ); 14 | bool operator !=( const Iter & ); 15 | operator bool() const; 16 | }; 17 | 18 | struct Container { 19 | typedef Iter iterator; 20 | iterator begin(); 21 | iterator end(); 22 | }; 23 | 24 | void iterate1( Container &c ) { 25 | typedef Container::iterator I; 26 | for( I i(c.begin()); 27 | i != c.end(); 28 | i++ ) // diagnostic 29 | ; 30 | for( I i(c.begin()); 31 | i != c.end(); 32 | ++i ) // no diagnostic 33 | ; 34 | I i(c.begin()); 35 | while (i != c.end() ) { 36 | i++; // diagnostic 37 | } 38 | Iter j; 39 | for( ; true; j++ ) // diagnostic 40 | ; 41 | for( ; true; ++j ) // no diagnostic 42 | ; 43 | j++; // diagnostic 44 | ++j; // no dignostic 45 | Iter k = j++; // no dignostic 46 | k = j++; // no diagnostic 47 | j.operator --(); // no diagnostic 48 | j.operator --(0); // diagnostic 49 | } 50 | 51 | template 52 | void iterate3( Cont &c ) { 53 | typedef typename Cont::iterator I; 54 | for( I i(c.begin()); i != c.end(); i++ ) // diagnostic 55 | ; 56 | } 57 | 58 | template 59 | void iterate4( Cont &c ) { 60 | typedef typename Cont::iterator I; 61 | for( I i(c.begin()); i != c.end(); ++i ) // no diagnostic 62 | ; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | 20 | How to include...?: 21 | 22 | DCL05 23 | DCL12 24 | DCL14 25 | EXP08 26 | INT15 27 | STR02 28 | MEM02 29 | MEM10 30 | ERR05 31 | 32 | 33 | Will not compile (on gcc 3.4.4): 34 | 35 | PRE01 36 | PRE30 37 | DCL07 38 | DCL09 39 | EXP36 40 | EXP38 41 | INT01 42 | STR07 43 | ARR31 44 | ARR35 45 | ERR03 46 | 47 | 48 | Not worthwhile at this time: 49 | 50 | INT03 51 | STR08 52 | SIG02 53 | ERR02 54 | POS00 55 | POS02 56 | POS31 57 | POS32 58 | MSC08 59 | MSC13 60 | 61 | */ 62 | 63 | #include "PRE_NCCE.c" 64 | #include "DCL_NCCE.c" 65 | #include "EXP_NCCE.c" 66 | #include "INT_NCCE.c" 67 | #include "FLP_NCCE.c" 68 | #include "ARR_NCCE.c" 69 | #include "STR_NCCE.c" 70 | #include "MEM_NCCE.c" 71 | 72 | #include "ENV_NCCE.c" 73 | #include "SIG_NCCE.c" 74 | #include "ERR_NCCE.c" 75 | #include "MSC_NCCE.c" 76 | #include "POS_NCCE.c" 77 | 78 | int main(int argc, char const *argv[], char const *envp[]) { 79 | PRE(); 80 | DCL(); 81 | EXP(); 82 | INT(); 83 | FLP(); 84 | ARR(); 85 | STR(); 86 | MEM(); 87 | 88 | ENV(envp); 89 | SIG(); 90 | ERR(); 91 | MSC(); 92 | POS(); 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /rosecheckers/test/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | /* 5 | // 6 | // CERT Rosecheckers 7 | // Copyright 2022 Carnegie Mellon University. 8 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 9 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 10 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 11 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 12 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 13 | // DM21-0505 14 | // 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | //#include <-- not working with G++, not needed for C 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | extern char **environ; 45 | 46 | /* This is for the case where we just want to run it through a static 47 | * analysis tool and don't care about runtime errors. This is not 48 | * specified as a #define to avoid being ignored by the tools. 49 | */ 50 | #define RUNTIME_IGNORE 1 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /rosecheckers/virtualCFG.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | // Generates a CFG dot file from a C file. 15 | 16 | #include "rose.h" 17 | #include "cfgToDot.h" 18 | using namespace std; 19 | 20 | int main(int argc, char *argv[]) { 21 | // Build the AST used by ROSE 22 | SgProject* sageProject = frontend(argc,argv); 23 | 24 | // Run internal consistency tests on AST 25 | AstTests::runAllTests(sageProject); 26 | 27 | // Print the CFG view of each procedure in the AST in Dot format to cout 28 | NodeQuerySynthesizedAttributeType functions = NodeQuery::querySubTree(sageProject, V_SgFunctionDefinition); 29 | for (NodeQuerySynthesizedAttributeType::const_iterator i = functions.begin(); i != functions.end(); ++i) { 30 | SgFunctionDefinition* proc = isSgFunctionDefinition(*i); 31 | if (proc) { 32 | // Print out the full CFG, including bookkeeping nodes 33 | // VirtualCFG::cfgToDotForDebugging(cout, proc->get_declaration()->get_name(), proc->cfgForBeginning()); 34 | // Print out only those nodes which are "interesting" for analyses 35 | VirtualCFG::cfgToDot(cout, proc->get_declaration()->get_name(), VirtualCFG::makeInterestingCfg(proc)); 36 | } 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_CPP_H 2 | #define UTIL_CPP_H 3 | 4 | /* 5 | // 6 | // CERT Rosecheckers 7 | // Copyright 2022 Carnegie Mellon University. 8 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 9 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 10 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 11 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 12 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 13 | // DM21-0505 14 | // 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | 49 | typedef unsigned int rsize_t; 50 | typedef int errno_t; 51 | 52 | extern char **environ; 53 | 54 | using namespace std; 55 | 56 | /* This is for the case where we just want to run it through a static 57 | * analysis tool and don't care about runtime errors. This is not 58 | * specified as a #define to avoid being ignored by the tools. 59 | */ 60 | 61 | #define RUNTIME_IGNORE 1 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/README: -------------------------------------------------------------------------------- 1 | Prerequesites 2 | ------------- 3 | 4 | This code has been developed and tested on an i386 workstation running Linux (2.6.16.60) and g++ (3.4.4) 5 | 6 | This code depends on ROSE 0.9.3a, which is available for free download from: 7 | 8 | http://rosecompiler.org/ 9 | 10 | ROSE 0.9.3a also depends on the BOOST C++ library, version 1.3.5, which is available for free download from: 11 | 12 | http://www.boost.org/ 13 | 14 | First make sure that the ROSE environment variable points to the build directory of ROSE: 15 | 16 | export ROSE=/usr/local/rose/compileTree 17 | 18 | 19 | Building Diagnose 20 | ----------------- 21 | 22 | To build the ROSE 'diagnose' program, which runs secure coding rules: 23 | 24 | make pgms 25 | 26 | To test diagnose on the code samples from the CERT C Secure Coding Rules: 27 | 28 | make tests 29 | 30 | To build API documentation pages, you must have doxygen installed: 31 | 32 | make doc 33 | 34 | To clean documentation pages and build files: 35 | 36 | make clean 37 | 38 | 39 | Running Diagnose 40 | ---------------- 41 | 42 | To run the diagnose program on a C file, simply pass the C file as an argument: 43 | 44 | diagnose hello.c 45 | 46 | If the C file violates some secure coding rules, the diagnose program will print them out. If the diagnose program can not find any violations, it prints nothing. 47 | 48 | 49 | Secure Coding Rules Enforced by Diagnose 50 | ---------------------------------------- 51 | 52 | The C Secure Coding Rules are available at: 53 | 54 | https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Secure+Coding+Standard 55 | 56 | Here is a breakdown of how thoroughly diagnose enforces the C Secure Coding Rules: 57 | 58 | Complete 57 59 | 60 | ROSE catches all violations of these rules 61 | 62 | Partial 45 63 | 64 | ROSE catches some, but not all violations of these rules 65 | 66 | false-positive 9 67 | 68 | These rules could be checked by diagnose, but they will also catch some false positives. 69 | 70 | Potential 29 71 | 72 | These rules are not checked by diagnose, but could be 73 | 74 | Undoable 32 75 | 76 | These rules could not be checked by ROSE due to various limitations in ROSE. 77 | 78 | Unenforceable 48 79 | 80 | These rules could not be checked by any tool that relies purely on unaided static analysis. 81 | 82 | 83 | TOTAL 220 84 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/diagnose.C: -------------------------------------------------------------------------------- 1 | /** 2 | * \file diagnose.C 3 | * 4 | * Copyright (c) 2007 Carnegie Mellon University. 5 | * All rights reserved. 6 | 7 | * Permission to use this software and its documentation for any purpose is 8 | * hereby granted, provided that the above copyright notice appear and that 9 | * both that copyright notice and this permission notice appear in supporting 10 | * documentation, and that the name of CMU not be used in advertising or 11 | * publicity pertaining to distribution of the software without specific, 12 | * written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 15 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 16 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 19 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | 23 | #include 24 | #include "rose.h" 25 | #include "utilities.h" 26 | 27 | extern bool PREPRO(const SgNode *node); 28 | extern bool DCL(const SgNode *node); 29 | extern bool EXP(const SgNode *node); 30 | extern bool ARR(const SgNode *node); 31 | extern bool FLP(const SgNode *node); 32 | extern bool INT(const SgNode *node); 33 | extern bool STR(const SgNode *node); 34 | extern bool MEM(const SgNode *node); 35 | extern bool FIO(const SgNode *node); 36 | extern bool ENV(const SgNode *node); 37 | extern bool SIG(const SgNode *node); 38 | extern bool ERR(const SgNode *node); 39 | extern bool MSC(const SgNode *node); 40 | extern bool POS(const SgNode *node); 41 | 42 | class visitorTraversal : public AstSimpleProcessing { 43 | public : 44 | visitorTraversal () {} 45 | virtual void visit(SgNode* node) { 46 | PREPRO(node); 47 | DCL(node); 48 | EXP(node); 49 | ARR(node); 50 | FLP(node); 51 | INT(node); 52 | STR(node); 53 | MEM(node); 54 | FIO(node); 55 | ENV(node); 56 | SIG(node); 57 | ERR(node); 58 | MSC(node); 59 | POS(node); 60 | } 61 | }; 62 | 63 | 64 | int main( int argc, char* argv[]) { 65 | SgProject* project = frontend(argc,argv); 66 | ROSE_ASSERT( project ); 67 | visitorTraversal exampleTraversal; 68 | exampleTraversal.traverseInputFiles( project, preorder); 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.EXP.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void EXP09_1() { 17 | const char* random1 = (char *)malloc(10); 18 | const unsigned char* random2 = (unsigned char*)malloc(20); 19 | const signed char* random3 = (signed char*)malloc(5); 20 | int **matrix = (int**) malloc( 10 * sizeof( int*)); 21 | matrix[0] = (int*)realloc( matrix[0], sizeof(int)*10); 22 | const char* random4 = (char *)malloc(sizeof(char)); 23 | } 24 | 25 | 26 | void* Malloc(size_t amt) { 27 | void* ptr; 28 | 29 | if(amt == 0) 30 | return NULL; 31 | 32 | ptr = (void*) malloc(amt); 33 | if (ptr == NULL) { 34 | printf("Memory error\n"); 35 | exit(1); 36 | } 37 | return ptr; 38 | } 39 | 40 | 41 | void EXP09_2() { 42 | const char* foo = (char*) Malloc(5); 43 | 44 | const size_t ptr_size = sizeof(char *); 45 | size_t i; 46 | 47 | if (ptr_size > SIZE_MAX/100) return; 48 | char **triarray = (char**) calloc(100, ptr_size); 49 | if (!triarray) { 50 | /* handle error */ 51 | } 52 | 53 | for (i = 0; i < 100; i++) { 54 | triarray[i] = (char*) calloc(20, 0 * 1 + 1 * 1 + 1 * 0); 55 | if (!triarray[i]) { 56 | /* handle error */ 57 | } 58 | } 59 | } 60 | 61 | void EXP05(const char *str, size_t slen) { 62 | const char *p = (const char *) str; 63 | 64 | printf("%p", p); 65 | } 66 | -------------------------------------------------------------------------------- /rosecheckers/Dockerfile: -------------------------------------------------------------------------------- 1 | # docker build -t rosebud . 2 | # docker run -it --rm rosebud rosecheckers example.c 3 | 4 | # 5 | # CERT Rosecheckers 6 | # Copyright 2022 Carnegie Mellon University. 7 | # NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 8 | # Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 9 | # [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 10 | # CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 11 | # This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 12 | # DM21-0505 13 | # 14 | 15 | FROM ubuntu:bionic 16 | 17 | RUN apt-get update \ 18 | && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 19 | software-properties-common \ 20 | && apt-get clean 21 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 22 | gcc g++ perl python make bison flex \ 23 | && apt-get clean 24 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 25 | build-essential fontconfig ghostscript gnupg groff imagemagick \ 26 | openjdk-8-jre-headless patch xz-utils \ 27 | && apt-get clean 28 | RUN add-apt-repository ppa:rosecompiler/rose-stable \ 29 | && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 30 | rose \ 31 | && apt-get clean 32 | # This used to also install rose-tools, but that dependency is currently broken 33 | 34 | # Needed by rosecheckers, but not rose 35 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 36 | libtool libtool-bin doxygen \ 37 | && apt-get clean 38 | 39 | ENV ROSE=/usr/rose 40 | ENV ROSECHECKERS=/usr/rosecheckers 41 | WORKDIR $ROSECHECKERS 42 | COPY . $ROSECHECKERS 43 | 44 | RUN make \ 45 | && make install \ 46 | && make doc \ 47 | && make clean 48 | 49 | 50 | CMD ["/bin/bash"] 51 | -------------------------------------------------------------------------------- /rosecheckers/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rosecheckers 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?name? 14 | 15 | 16 | 17 | org.eclipse.cdt.make.core.append_environment 18 | true 19 | 20 | 21 | org.eclipse.cdt.make.core.autoBuildTarget 22 | all 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | make 31 | 32 | 33 | org.eclipse.cdt.make.core.cleanBuildTarget 34 | clean 35 | 36 | 37 | org.eclipse.cdt.make.core.contents 38 | org.eclipse.cdt.make.core.activeConfigSettings 39 | 40 | 41 | org.eclipse.cdt.make.core.enableAutoBuild 42 | false 43 | 44 | 45 | org.eclipse.cdt.make.core.enableCleanBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.enableFullBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.fullBuildTarget 54 | all 55 | 56 | 57 | org.eclipse.cdt.make.core.stopOnError 58 | true 59 | 60 | 61 | org.eclipse.cdt.make.core.useDefaultBuildCmd 62 | true 63 | 64 | 65 | 66 | 67 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 68 | 69 | 70 | 71 | 72 | 73 | org.eclipse.cdt.core.ccnature 74 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 75 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 76 | org.eclipse.cdt.core.cnature 77 | 78 | 79 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.xtra.POS.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | 17 | int POS34_1(char const *var) { 18 | static char *oldenv; 19 | char const *env_format = "TEST=%s"; 20 | size_t const len = strlen(var) + strlen(env_format); 21 | char *environment = (char *) calloc( len, 256); 22 | if (environment == NULL) { 23 | return -1; 24 | } 25 | const int rc = snprintf(environment, len, env_format, var); 26 | if (rc < 0 || (size_t)rc >= len) { 27 | /* Handle Error */ 28 | } 29 | if (putenv(environment) != 0) { 30 | free(environment); 31 | return -1; 32 | } 33 | if (oldenv != NULL) 34 | free(oldenv); // avoid memory leak 35 | oldenv = environment; 36 | return 0; 37 | } 38 | 39 | 40 | char goodenv[1024]; 41 | 42 | int POS34_2(const char *var) { 43 | char *environment; 44 | environment = goodenv; 45 | 46 | if (snprintf(environment, sizeof(environment),"TEST=%s", var) < 0) { 47 | /* Handle error */ 48 | } 49 | 50 | return putenv(environment); 51 | } 52 | 53 | 54 | char env0[1024]; 55 | int POS34_3(const char *var) { 56 | 57 | if (snprintf(env0, sizeof(env0),"TEST=%s", var) < 0) { 58 | /* Handle error */ 59 | } 60 | 61 | return putenv(env0); 62 | } 63 | 64 | const char *spongeBob = "bob the sponge, here again!!!"; 65 | int POS34_4(){ 66 | return putenv((char*) spongeBob); // const cast necessary for putenv 67 | } 68 | 69 | 70 | int POS34_5(const char *var) { 71 | static char environment[1024]; 72 | 73 | if (snprintf(environment, sizeof(environment),"TEST=%s", var) < 0) { 74 | /* Handle error */ 75 | } 76 | 77 | return putenv(environment); 78 | } 79 | 80 | int POS34_6(){ 81 | char *env_1 = (char*)(malloc(10)); 82 | if (env_1 == NULL) {/* handle error */} 83 | char *env_2 = env_1; 84 | return putenv(env_2); 85 | } 86 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/cce/ERR_CS.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void ERR01(); 21 | void ERR04(); 22 | void ERR06(); 23 | void ERR30(); 24 | void ERR31(); 25 | void ERR32(); 26 | 27 | 28 | void ERR() { 29 | ERR01(); 30 | ERR04(); 31 | ERR06(); 32 | ERR30(); 33 | ERR31(); 34 | ERR32(); 35 | } 36 | 37 | 38 | /* ERR01_A v.27 */ 39 | 40 | void ERR01() { 41 | printf("This\n"); 42 | printf("is\n"); 43 | printf("a\n"); 44 | printf("test.\n"); 45 | if (ferror(stdout)) { 46 | fprintf(stderr, "printf failed\n"); 47 | } 48 | } 49 | 50 | 51 | /* ERR04_A v.40 */ 52 | 53 | void ERR04() { 54 | char const *filename = "hello.txt"; 55 | FILE *f = fopen(filename, "w"); 56 | if (f == NULL) { 57 | /* handle error */ 58 | } 59 | fprintf(f, "Hello, World\n"); 60 | 61 | exit(EXIT_FAILURE); 62 | } 63 | 64 | 65 | /* ERR06_A v.14 */ 66 | 67 | void ERR06_cleanup(void) { 68 | /* delete temporary files, restore consistent state, etc. */ 69 | } 70 | 71 | void ERR06() { 72 | if (atexit(ERR06_cleanup) != 0) { 73 | /* Handle Error */ 74 | } 75 | 76 | if(1) 77 | exit(EXIT_FAILURE); 78 | } 79 | 80 | 81 | /* ERR30_C v.38 */ 82 | 83 | void ERR30() { 84 | unsigned long number; 85 | char *string = NULL; 86 | char *endptr; 87 | 88 | /* ... */ 89 | 90 | errno = 0; 91 | number = strtoul(string, &endptr, 0); 92 | if (endptr == string || (number == ULONG_MAX 93 | && errno == ERANGE)) 94 | { 95 | /* handle the error */ 96 | } 97 | else { 98 | /* computation succeeded */ 99 | } 100 | } 101 | 102 | 103 | /* ERR31_C v.22 */ 104 | 105 | #include 106 | 107 | void ERR31() {} 108 | 109 | 110 | /* ERR32_C v.29 */ 111 | 112 | typedef void (*ERR32_pfv)(int); 113 | 114 | void ERR32_handler(int signum) { 115 | const ERR32_pfv old_handler = signal(signum, SIG_DFL); 116 | if (old_handler == SIG_ERR) { 117 | abort(); 118 | } 119 | } 120 | 121 | void ERR32() { 122 | const ERR32_pfv old_handler = signal(SIGINT, ERR32_handler); 123 | if (old_handler == SIG_ERR) { 124 | perror("SIGINT handler"); 125 | /* handle error condition */ 126 | } 127 | 128 | /* main code loop */ 129 | 130 | return; 131 | } 132 | -------------------------------------------------------------------------------- /cpp_rules/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2007 Carnegie Mellon University. 3 | # All rights reserved. 4 | # 5 | # Permission to use this software and its documentation for any purpose is hereby granted, 6 | # provided that the above copyright notice appear and that both that copyright notice and 7 | # this permission notice appear in supporting documentation, and that the name of CMU not 8 | # be used in advertising or publicity pertaining to distribution of the software without 9 | # specific, written prior permission. 10 | # 11 | # CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | # OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | 18 | # You should have ROSE predefined 19 | 20 | 21 | # Change this to your own installation of ROSE 22 | DIAGNOSE_CMD = env LD_LIBRARY_PATH=${ROSE}/lib ./diagnose 23 | 24 | # Location of include directory after "make install" 25 | ROSE_INCLUDE_DIR = $(ROSE)/include 26 | 27 | # Location of library directory after "make install" 28 | ROSE_LIB_DIR = $(ROSE)/lib 29 | 30 | # We can't use automake conditional support here 31 | # Support for Gabriel's QRose GUI Library 32 | QT_LDFLAGS = 33 | LIB_QT = 34 | 35 | # DQ (8/14/2005): Updated from $(top_srcdir)/config/Makefile.for.ROSE.includes.and.libs 36 | ROSE_LIBS = -lrose -lfl -lm -lrt $(MYSQL_DATABASE_LIBS) $(LIB_QT) 37 | 38 | 39 | # Default make rule to use 40 | all: pgms tests 41 | 42 | pgms: diagnose 43 | diagnose: diagnose.o \ 44 | EXP.o \ 45 | OBJ.o \ 46 | DCL.o \ 47 | ERR.o \ 48 | FLP.o \ 49 | RES.o \ 50 | type.o \ 51 | utilities.o 52 | libtool --mode=link g++ -Wall -g -o diagnose -L$(ROSE)/lib $(ROSE_LIBS) $^ 53 | 54 | %.o: %.C 55 | libtool --mode=compile g++ -c -g -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) -o $@ $< 56 | 57 | tests: cce.test ncce.test 58 | 59 | ncce.output: diagnose 60 | @echo > $@ 61 | @for file in ncce/*.c ; do ${DIAGNOSE_CMD} $$file >> $@ 2>&1 ; echo Ran $$file; done 62 | @perl -p -i -e "s|${PWD}|\.|;" $@ 63 | @perl -p -i -e 's|diagnose: .*/EDG_SAGE_Connection|diagnose: .../EDGE_SAGE_Connection|;' $@ 64 | @perl -n -i -e 'print if (!/Aborted/);' $@ 65 | 66 | cce.output: diagnose 67 | @echo > $@ 68 | @for file in cce/*.c ; do ${DIAGNOSE_CMD} $$file >> $@ 2>&1 ; echo Ran $$file; done 69 | @perl -p -i -e "s|${PWD}|\.|;" $@ 70 | @perl -p -i -e 's|diagnose: .*/EDG_SAGE_Connection|diagnose: .../EDGE_SAGE_Connection|;' $@ 71 | @perl -n -i -e 'print if (!/Aborted/);' $@ 72 | 73 | %.test: %.output %.ans 74 | @echo "Checking $*" 75 | @-if [ -n "`cmp $*.output $*.ans 2>&1`" ]; then \ 76 | echo "WARNING: $* failure" ;\ 77 | diff -u $*.ans $*.output ;\ 78 | fi 79 | 80 | clean: 81 | -libtool --mode=clean rm diagnose *flymake.C *.o *.output *~ *# */*.o *.lo .libs nul */*~ */*# 82 | 83 | 84 | # support for flymake.el 85 | check-syntax: 86 | g++ -Wall -o nul -S -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) ${CHK_SOURCES} 87 | #check-syntax: 88 | # ${DIAGNOSE_CMD} --edg:brief_diagnostics -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) ${CHK_SOURCES} 89 | -------------------------------------------------------------------------------- /rosecheckers/license.txt: -------------------------------------------------------------------------------- 1 | CERT Rosecheckers 2 | Copyright 2022 Carnegie Mellon University. 3 | BSD (SEI) 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Products derived from this software may not include “Carnegie Mellon University,” "SEI” and/or “Software Engineering Institute" in the name of such derived product, nor shall “Carnegie Mellon University,” "SEI” and/or “Software Engineering Institute" be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact permission@sei.cmu.edu. 12 | 13 | ACKNOWLEDGMENTS AND DISCLAIMERS: 14 | 15 | CERT Rosecheckers includes and/or can make use of certain additional software dependencies ("Additional Software Dependencies"). The Additional Software Dependencies that are used by CERT Rosecheckers are dependent upon your system configuration, but typically includes the software identified in the documentation and/or ReadMe files. By using CERT Rosecheckers, You agree to comply with any and all relevant Additional Software Dependencies terms and conditions contained in any such Additional Software Dependencies or separate license file distributed with such Additional Software Dependencies. The parties who own the Additional Software Dependencies ("Third Party Licensors") are intended third party beneficiaries to this License with respect to the terms applicable to their Additional Software Dependencies. Additional Software Dependencies licenses only apply to the Additional Software Dependencies and not any other portion of CERT Rosecheckers or CERT Rosecheckers as a whole. 16 | 17 | This material is based upon work funded and supported by the Department of Defense under Contract No. FA8702-15-D-0002 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center. 18 | 19 | The view, opinions, and/or findings contained in this material are those of the author(s) and should not be construed as an official Government position, policy, or decision, unless designated by other documentation. 20 | 21 | NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 22 | 23 | [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 24 | 25 | CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 26 | 27 | DM21-0505 28 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/ERR_NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void ERR01(); 21 | void ERR04(); 22 | void ERR06(); 23 | void ERR30(); 24 | void ERR31(); 25 | void ERR32(); 26 | 27 | 28 | void ERR() { 29 | ERR01(); 30 | ERR04(); 31 | ERR06(); 32 | ERR30(); 33 | ERR31(); 34 | ERR32(); 35 | } 36 | 37 | 38 | /* ERR01_A v.27 */ 39 | 40 | void ERR01() { 41 | errno = 0; 42 | printf("This\n"); 43 | printf("is\n"); 44 | printf("a\n"); 45 | printf("test.\n"); 46 | if (errno != 0) { 47 | fprintf(stderr, "printf failed: %s\n", strerror(errno)); 48 | } 49 | } 50 | 51 | 52 | /* ERR04_A v.40 */ 53 | 54 | void ERR04() { 55 | char const *filename = "hello.txt"; 56 | FILE *f = fopen(filename, "w"); 57 | if (f == NULL) { 58 | /* handle error */ 59 | } 60 | fprintf(f, "Hello, World\n"); 61 | 62 | abort(); /* oops! data might not get written! */ 63 | } 64 | 65 | 66 | /* ERR06_A v.14 */ 67 | 68 | void ERR06_cleanup(void) { 69 | /* delete temporary files, restore consistent state, etc. */ 70 | } 71 | 72 | void ERR06() { 73 | if (atexit(ERR06_cleanup) != 0) { 74 | /* Handle Error */ 75 | } 76 | 77 | assert(1); 78 | } 79 | 80 | 81 | /* ERR30_C v.38 */ 82 | 83 | void ERR30() { 84 | unsigned long number; 85 | char *string = NULL; 86 | char *endptr; 87 | 88 | /* ... */ 89 | 90 | number = strtoul(string, &endptr, 0); 91 | if (endptr == string || (number == ULONG_MAX 92 | && errno == ERANGE)) 93 | { 94 | /* handle the error */ 95 | } 96 | else { 97 | /* computation succeeded */ 98 | } 99 | } 100 | 101 | 102 | /* ERR31_C v.22 */ 103 | 104 | extern int errno; 105 | 106 | void ERR31() {} 107 | 108 | 109 | /* ERR32_C v.29 */ 110 | 111 | typedef void (*ERR32_pfv)(int); 112 | 113 | void ERR32_handler(int signum) { 114 | const ERR32_pfv old_handler = signal(signum, SIG_DFL); 115 | if (old_handler == SIG_ERR) { 116 | perror("SIGINT handler"); /* undefined behavior */ 117 | /* handle error condition */ 118 | } 119 | } 120 | 121 | void ERR32() { 122 | const ERR32_pfv old_handler = signal(SIGINT, ERR32_handler); 123 | if (old_handler == SIG_ERR) { 124 | perror("SIGINT handler"); 125 | /* handle error condition */ 126 | } 127 | 128 | /* main code loop */ 129 | 130 | return; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /rosecheckers/test/c.cce.wiki.ERR.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void ERR01(); 17 | void ERR04(); 18 | void ERR06(); 19 | void ERR30(); 20 | void ERR31(); 21 | void ERR32(); 22 | 23 | 24 | void ERR() { 25 | ERR01(); 26 | ERR04(); 27 | ERR06(); 28 | ERR30(); 29 | ERR31(); 30 | ERR32(); 31 | } 32 | 33 | 34 | /* ERR01_A v.27 */ 35 | 36 | void ERR01() { 37 | printf("This\n"); 38 | printf("is\n"); 39 | printf("a\n"); 40 | printf("test.\n"); 41 | if (ferror(stdout)) { 42 | fprintf(stderr, "printf failed\n"); 43 | } 44 | } 45 | 46 | 47 | /* ERR04_A v.40 */ 48 | 49 | void ERR04() { 50 | char const *filename = "hello.txt"; 51 | FILE *f = fopen(filename, "w"); 52 | if (f == NULL) { 53 | /* handle error */ 54 | } 55 | fprintf(f, "Hello, World\n"); 56 | 57 | exit(EXIT_FAILURE); 58 | } 59 | 60 | 61 | /* ERR06_A v.14 */ 62 | 63 | void ERR06_cleanup(void) { 64 | /* delete temporary files, restore consistent state, etc. */ 65 | } 66 | 67 | void ERR06() { 68 | if (atexit(ERR06_cleanup) != 0) { 69 | /* Handle Error */ 70 | } 71 | 72 | if(1) 73 | exit(EXIT_FAILURE); 74 | } 75 | 76 | 77 | /* ERR30_C v.38 */ 78 | 79 | void ERR30() { 80 | unsigned long number; 81 | char *string = NULL; 82 | char *endptr; 83 | 84 | /* ... */ 85 | 86 | errno = 0; 87 | number = strtoul(string, &endptr, 0); 88 | if (endptr == string || (number == ULONG_MAX 89 | && errno == ERANGE)) 90 | { 91 | /* handle the error */ 92 | } 93 | else { 94 | /* computation succeeded */ 95 | } 96 | } 97 | 98 | 99 | /* ERR31_C v.22 */ 100 | 101 | #include 102 | 103 | void ERR31() {} 104 | 105 | 106 | /* ERR32_C v.29 */ 107 | 108 | typedef void (*ERR32_pfv)(int); 109 | 110 | void ERR32_handler(int signum) { 111 | const ERR32_pfv old_handler = signal(signum, SIG_DFL); 112 | if (old_handler == SIG_ERR) { 113 | abort(); 114 | } 115 | } 116 | 117 | void ERR32() { 118 | const ERR32_pfv old_handler = signal(SIGINT, ERR32_handler); 119 | if (old_handler == SIG_ERR) { 120 | perror("SIGINT handler"); 121 | /* handle error condition */ 122 | } 123 | 124 | /* main code loop */ 125 | 126 | return; 127 | } 128 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ERR.C: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ERR.C 3 | * 4 | * \note As written, these tests catch template declarations only if 5 | * instantiated. 6 | * 7 | * Copyright (c) 2007 Carnegie Mellon University. 8 | * All rights reserved. 9 | 10 | * Permission to use this software and its documentation for any purpose is 11 | * hereby granted, provided that the above copyright notice appear and that 12 | * both that copyright notice and this permission notice appear in supporting 13 | * documentation, and that the name of CMU not be used in advertising or 14 | * publicity pertaining to distribution of the software without specific, 15 | * written prior permission. 16 | * 17 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 18 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 19 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 21 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 22 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23 | */ 24 | 25 | #include "rose.h" 26 | #include "utilities.h" 27 | 28 | /** 29 | * Understand the termination behavior of assert() and abort() 30 | */ 31 | bool ERR06_C( const SgNode *node ) { 32 | const SgFunctionRefExp *fnRef = isSgFunctionRefExp(node); 33 | if (!(fnRef && isCallOfFunctionNamed(fnRef, "abort"))) 34 | return false; 35 | 36 | std::set fds; 37 | 38 | FOREACH_SUBNODE(findParentOfType(fnRef, SgFunctionDefinition), nodes, i, V_SgFunctionRefExp) { 39 | const SgFunctionRefExp *iFn = isSgFunctionRefExp(*i); 40 | assert(iFn); 41 | if (iFn == fnRef) 42 | break; 43 | 44 | if (isCallOfFunctionNamed(iFn, "open") 45 | ||isCallOfFunctionNamed(iFn, "fopen") 46 | ||isCallOfFunctionNamed(iFn, "mkstemp")) { 47 | const SgInitializedName *var = getVarAssignedTo(iFn, NULL); 48 | if (var && !(isGlobalVar(var) || isStaticVar(var))) { 49 | fds.insert(var); 50 | } 51 | } else if (isCallOfFunctionNamed(iFn, "close") 52 | ||isCallOfFunctionNamed(iFn, "open")) { 53 | const SgVarRefExp *varRef = isSgVarRefExp(removeImplicitPromotions(getFnArg(iFn, 0))); 54 | if (!varRef) 55 | continue; 56 | const SgInitializedName *var = getRefDecl(varRef); 57 | assert(var); 58 | fds.erase(fds.find(var)); 59 | } 60 | } 61 | 62 | if (fds.size() > 0) { 63 | print_error(node, "ERR06-C", "Understand the termination behavior of assert() and abort()", true); 64 | return true; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | /** 71 | * Don't redefine errno 72 | * 73 | * \note If the program includes errno.h than errno is a macro, so we won't be 74 | * able to flag this declaration 75 | */ 76 | bool ERR31_C( const SgNode *node ) { 77 | const SgVariableDeclaration *varDecl = isSgVariableDeclaration(node); 78 | if (!varDecl) 79 | return false; 80 | bool violation = false; 81 | FOREACH_INITNAME(varDecl->get_variables(), i) { 82 | const SgInitializedName *var = isSgInitializedName(*i); 83 | assert(var); 84 | if (var->get_name().getString() == "errno") { 85 | print_error(node, "ERR31-C", "Don't redefine errno"); 86 | violation = true; 87 | } 88 | } 89 | return violation; 90 | } 91 | 92 | bool ERR(const SgNode *node) { 93 | bool violation = false; 94 | violation |= ERR06_C(node); 95 | violation |= ERR31_C(node); 96 | return violation; 97 | } 98 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.ENV.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | #include "cpp.util.h" 16 | #include 17 | 18 | void ENV00(); 19 | void ENV01(); 20 | void ENV02(); 21 | void ENV03(); 22 | void ENV04(); 23 | void ENV30(); 24 | void ENV31(char const *envp[]); 25 | void ENV32(); 26 | 27 | void ENV(char const *envp[]) { 28 | ENV00(); 29 | ENV01(); 30 | ENV02(); 31 | ENV03(); 32 | ENV04(); 33 | ENV30(); 34 | ENV31(envp); 35 | ENV32(); 36 | } 37 | 38 | void ENV00(void) { 39 | char *tmpvar; 40 | char *tempvar; 41 | 42 | tmpvar = getenv("TMP"); 43 | if (!tmpvar) return; 44 | tempvar = getenv("TEMP"); 45 | if (!tempvar) return; 46 | } 47 | 48 | void ENV01(void) { 49 | char copy[16]; 50 | const char *temp = getenv("TEST_ENV"); 51 | if (temp != NULL) { 52 | strcpy(copy, temp); 53 | } 54 | } 55 | 56 | void ENV02(void) { 57 | if (putenv("TEST_ENV=foo") != 0) { 58 | return; 59 | } 60 | if (putenv("Test_ENV=bar") != 0) { 61 | return; 62 | } 63 | 64 | const char *temp = getenv("TEST_ENV"); 65 | } 66 | 67 | void ENV03(void) { 68 | if (system("/bin/ls dir.`date +%Y%m%d`") == -1) { 69 | return; 70 | } 71 | } 72 | 73 | void ENV04(void) { 74 | char *input = NULL; 75 | /* input gets initialized by user */ 76 | 77 | char cmdbuf[512]; 78 | int len_wanted = snprintf( 79 | cmdbuf, sizeof(cmdbuf), "any_cmd '%s'", input 80 | ); 81 | if (len_wanted >= sizeof(cmdbuf)) { 82 | perror("Input too long"); 83 | } 84 | else if (len_wanted < 0) { 85 | perror("Encoding error"); 86 | } 87 | else if (system(cmdbuf) == -1) { 88 | perror("Error executing input"); 89 | } 90 | } 91 | 92 | void ENV30(void) { 93 | char *env = getenv("TEST_ENV"); 94 | if (env == NULL) { 95 | return; 96 | } 97 | env[0] = 'a'; 98 | } 99 | 100 | void ENV31(char const *envp[]) { 101 | size_t i; 102 | if (setenv("MY_NEW_VAR", "new_value", 1) != 0) { 103 | return; 104 | } 105 | if (envp != NULL) { 106 | for (i = 0; envp[i] != NULL; i++) { 107 | if (puts(envp[i]) == EOF) { 108 | return; 109 | } 110 | } 111 | } 112 | } 113 | 114 | void ENV32_exit1() { 115 | exit(0); 116 | } 117 | 118 | void ENV32(void) { 119 | if (atexit(ENV32_exit1) != 0) { 120 | return; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.ERR.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void ERR01(); 17 | void ERR04(); 18 | void ERR06(); 19 | void ERR30(); 20 | void ERR31(); 21 | void ERR32(); 22 | 23 | 24 | void ERR() { 25 | ERR01(); 26 | ERR04(); 27 | ERR06(); 28 | ERR30(); 29 | ERR31(); 30 | ERR32(); 31 | } 32 | 33 | 34 | /* ERR01_A v.27 */ 35 | 36 | void ERR01() { 37 | errno = 0; 38 | printf("This\n"); 39 | printf("is\n"); 40 | printf("a\n"); 41 | printf("test.\n"); 42 | if (errno != 0) { 43 | fprintf(stderr, "printf failed: %s\n", strerror(errno)); 44 | } 45 | } 46 | 47 | 48 | /* ERR04_A v.40 */ 49 | 50 | void ERR04() { 51 | char const *filename = "hello.txt"; 52 | FILE *f = fopen(filename, "w"); 53 | if (f == NULL) { 54 | /* handle error */ 55 | } 56 | fprintf(f, "Hello, World\n"); 57 | 58 | abort(); /* oops! data might not get written! */ 59 | } 60 | 61 | 62 | /* ERR06_A v.14 */ 63 | 64 | void ERR06_cleanup(void) { 65 | /* delete temporary files, restore consistent state, etc. */ 66 | } 67 | 68 | void ERR06() { 69 | if (atexit(ERR06_cleanup) != 0) { 70 | /* Handle Error */ 71 | } 72 | 73 | assert(1); 74 | } 75 | 76 | 77 | /* ERR30_C v.38 */ 78 | 79 | void ERR30() { 80 | unsigned long number; 81 | char *string = NULL; 82 | char *endptr; 83 | 84 | /* ... */ 85 | 86 | number = strtoul(string, &endptr, 0); 87 | if (endptr == string || (number == ULONG_MAX 88 | && errno == ERANGE)) 89 | { 90 | /* handle the error */ 91 | } 92 | else { 93 | /* computation succeeded */ 94 | } 95 | } 96 | 97 | 98 | /* ERR31_C v.22 */ 99 | 100 | extern int errno; 101 | 102 | void ERR31() {} 103 | 104 | 105 | /* ERR32_C v.29 */ 106 | 107 | typedef void (*ERR32_pfv)(int); 108 | 109 | void ERR32_handler(int signum) { 110 | const ERR32_pfv old_handler = signal(signum, SIG_DFL); 111 | if (old_handler == SIG_ERR) { 112 | perror("SIGINT handler"); /* undefined behavior */ 113 | /* handle error condition */ 114 | } 115 | } 116 | 117 | void ERR32() { 118 | const ERR32_pfv old_handler = signal(SIGINT, ERR32_handler); 119 | if (old_handler == SIG_ERR) { 120 | perror("SIGINT handler"); 121 | /* handle error condition */ 122 | } 123 | 124 | /* main code loop */ 125 | 126 | return; 127 | } 128 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.SIG.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | #include "cpp.util.h" 16 | 17 | void SIG00(); 18 | void SIG01(); 19 | void SIG30(); 20 | 21 | void SIG() { 22 | SIG00(); 23 | SIG01(); 24 | SIG30(); 25 | } 26 | 27 | volatile sig_atomic_t SIG00_sig1 = 0; 28 | volatile sig_atomic_t SIG00_sig2 = 0; 29 | 30 | void SIG00_handler(int signum) { 31 | if (signum == SIGUSR1) { 32 | SIG00_sig1 = 1; 33 | } 34 | else if (SIG00_sig1) { 35 | SIG00_sig2 = 1; 36 | } 37 | } 38 | 39 | void SIG00(void) { 40 | struct sigaction act; 41 | act.sa_handler = &SIG00_handler; 42 | act.sa_flags = 0; 43 | if (sigemptyset(&act.sa_mask) != 0) { 44 | return; 45 | } 46 | if (sigaddset(&act.sa_mask, SIGUSR1)) { 47 | return; 48 | } 49 | if (sigaddset(&act.sa_mask, SIGUSR2)) { 50 | return; 51 | } 52 | 53 | if (sigaction(SIGUSR1, &act, NULL) != 0) { 54 | return; 55 | } 56 | if (sigaction(SIGUSR2, &act, NULL) != 0) { 57 | return; 58 | } 59 | 60 | while (SIG00_sig2 == 0) { 61 | /* Do nothing or give up CPU for a while */ 62 | } 63 | } 64 | 65 | void SIG01_handler(int signum) { 66 | #ifndef WINDOWS 67 | if (signal(signum, SIG_DFL) == SIG_ERR) { 68 | /* Handler error */ 69 | } 70 | #endif 71 | /* Handle signal */ 72 | } 73 | 74 | void SIG01(void) { 75 | struct sigaction act; 76 | act.sa_handler = &SIG01_handler; 77 | act.sa_flags = SA_RESETHAND; 78 | if (sigemptyset(&act.sa_mask) != 0) { 79 | return; 80 | } 81 | if (sigaction(SIGUSR1, &act, NULL) != 0) { 82 | return; 83 | } 84 | } 85 | 86 | volatile sig_atomic_t SIG30_eflag = 0; 87 | char *SIG30_info = NULL; 88 | 89 | void SIG30_log_message(void) { 90 | fprintf(stderr, SIG30_info); 91 | } 92 | 93 | void SIG30_handler(int signum) { 94 | SIG30_eflag = 1; 95 | } 96 | 97 | /* This is the same cce code for SIG31, SIG33, and SIG34 */ 98 | void SIG30(void) { 99 | if (signal(SIGINT, SIG30_handler) == SIG_ERR) { 100 | return; 101 | } 102 | SIG30_info = (char*)malloc(12); 103 | if (SIG30_info == NULL) { 104 | return; 105 | } 106 | 107 | while (!SIG30_eflag) { 108 | /* Main loop program code */ 109 | 110 | SIG30_log_message(); 111 | 112 | /* More program code */ 113 | } 114 | 115 | SIG30_log_message(); 116 | free(SIG30_info); 117 | SIG30_info = NULL; 118 | } 119 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2007 Carnegie Mellon University. 3 | # All rights reserved. 4 | # 5 | # Permission to use this software and its documentation for any purpose is hereby granted, 6 | # provided that the above copyright notice appear and that both that copyright notice and 7 | # this permission notice appear in supporting documentation, and that the name of CMU not 8 | # be used in advertising or publicity pertaining to distribution of the software without 9 | # specific, written prior permission. 10 | # 11 | # CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | # OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | # 17 | 18 | 19 | # You should have ROSE predefined to point to ROSE 20 | # and you should have BOOST defined to point to BOOST 21 | # To run 'diagnose' you should set LD_LIBRARY_PATH as shown below. 22 | 23 | # Change this to your own installation of ROSE 24 | DIAGNOSE_CMD = env LD_LIBRARY_PATH=${ROSE}/lib:${BOOST}/lib ./diagnose 25 | 26 | # Location of include directory after "make install" 27 | ROSE_INCLUDE_DIR = $(ROSE)/include 28 | 29 | # Location of library directory after "make install" 30 | ROSE_LIB_DIR = $(ROSE)/lib 31 | 32 | # We can't use automake conditional support here 33 | # Support for Gabriel's QRose GUI Library 34 | QT_LDFLAGS = 35 | LIB_QT = 36 | 37 | # DQ (8/14/2005): Updated from $(top_srcdir)/config/Makefile.for.ROSE.includes.and.libs 38 | ROSE_LIBS = -lrose -lfl -lm -lrt $(MYSQL_DATABASE_LIBS) $(LIB_QT) 39 | 40 | 41 | # Default make rule to use 42 | all: pgms tests 43 | 44 | pgms: diagnose 45 | diagnose: diagnose.o \ 46 | PRE.o \ 47 | DCL.o \ 48 | EXP.o \ 49 | ARR.o \ 50 | FLP.o \ 51 | INT.o \ 52 | STR.o \ 53 | MEM.o \ 54 | FIO.o \ 55 | ENV.o \ 56 | SIG.o \ 57 | ERR.o \ 58 | MSC.o \ 59 | POS.o \ 60 | categories.o\ 61 | value.o\ 62 | utilities.o 63 | libtool --mode=link g++ -Wall -g -o diagnose -L$(ROSE)/lib $(ROSE_LIBS) $^ 64 | 65 | %.o: %.C 66 | libtool --mode=compile g++ -Wall -c -g -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) -o $@ $< 67 | 68 | tests: cce.test ncce.test 69 | 70 | ncce.output: diagnose 71 | @echo > $@ 72 | @for file in ncce/*_NCCE.c ; do ${DIAGNOSE_CMD} $$file >> $@ 2>&1 ; echo Ran $$file; done 73 | @perl -p -i -e "s|${PWD}|\.|;" $@ 74 | @perl -p -i -e 's|diagnose: .*/EDG_SAGE_Connection|diagnose: .../EDGE_SAGE_Connection|;' $@ 75 | @perl -n -i -e 'print if (!/Aborted/);' $@ 76 | 77 | cce.output: diagnose 78 | @echo > $@ 79 | @for file in cce/*_CS.c ; do ${DIAGNOSE_CMD} $$file >> $@ 2>&1 ; echo Ran $$file; done 80 | @perl -p -i -e "s|${PWD}|\.|;" $@ 81 | @perl -p -i -e 's|diagnose: .*/EDG_SAGE_Connection|diagnose: .../EDGE_SAGE_Connection|;' $@ 82 | @perl -n -i -e 'print if (!/Aborted/);' $@ 83 | 84 | %.test: %.output %.ans 85 | @echo "Checking $*" 86 | @-if [ -n "`cmp $*.output $*.ans 2>&1`" ]; then \ 87 | echo "WARNING: $* failure" ;\ 88 | diff -u $*.ans $*.output ;\ 89 | fi 90 | 91 | clean: 92 | -libtool --mode=clean rm diagnose a.out *flymake.ti *flymake.C *.o *.output *~ *# */*.o *.lo .libs nul */*~ */*# 93 | 94 | doc: 95 | @echo "bulding documentation..." 96 | doxygen Doxyfile 97 | 98 | # support for flymake.el 99 | check-syntax: 100 | gcc -std=c99 -Wall -o nul -S -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) ${CHK_SOURCES} 101 | #check-syntax: 102 | # ${DIAGNOSE_CMD} --edg:no_wrap_diagnostics --edg:remarks --edg:display_error_number -DHAVE_CONFIG_H -I$(ROSE_INCLUDE_DIR) ${CHK_SOURCES} 103 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/POS_NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void POS30(); 21 | void POS33(); 22 | void POS34(); 23 | void POS35(); 24 | void POS36(); 25 | void POS37(); 26 | 27 | void POS() { 28 | POS30(); 29 | POS33(); 30 | POS34(); 31 | POS35(); 32 | POS36(); 33 | POS37(); 34 | } 35 | 36 | 37 | /* POS30_C v.33 */ 38 | 39 | void POS30() { 40 | char buf[1024]; 41 | const ssize_t len = readlink("/usr/bin/perl", buf, sizeof(buf)); 42 | buf[len] = '\0'; 43 | } 44 | 45 | 46 | /* POS33_C v.41 */ 47 | 48 | void POS33() { 49 | const char *filename = "foo"; 50 | 51 | const pid_t pid = vfork(); 52 | if ( pid == 0 ) /* child */ { 53 | if (execve(filename, NULL, NULL) == -1) { 54 | /* Handle Error */ 55 | } 56 | _exit(1); /* in case execve() fails */ 57 | } 58 | } 59 | 60 | 61 | /* POS34_C v.76 */ 62 | 63 | int POS34_func(char const *var) { 64 | char env[1024]; 65 | 66 | if (snprintf(env, sizeof(env),"TEST=%s", var) < 0) { 67 | /* Handle Error */ 68 | } 69 | 70 | return putenv(env); 71 | } 72 | 73 | void POS34() { 74 | int a = POS34_func("hello"); 75 | ++a; 76 | } 77 | 78 | 79 | /* POS35_C v.33 */ 80 | 81 | void POS35() { 82 | const char *filename = "foo"; 83 | char userbuf[] = "foo"; 84 | const unsigned int userlen = sizeof(userbuf); 85 | 86 | struct stat lstat_info; 87 | int fd; 88 | 89 | if (lstat(filename, &lstat_info) == -1) { 90 | /* handle error */ 91 | } 92 | if (!S_ISLNK(lstat_info.st_mode)) { 93 | if ((fd = open(filename, O_RDWR)) == -1) { 94 | /* handle error */ 95 | } 96 | } 97 | if (write(fd, userbuf, userlen) < userlen) { 98 | /* Handle Error */ 99 | } 100 | 101 | close(fd); 102 | } 103 | 104 | 105 | /* POS36_C v.19 */ 106 | 107 | void POS36() { 108 | /* Drop superuser privileges in incorrect order */ 109 | 110 | if (setuid(getuid()) == -1) { 111 | /* handle error condition */ 112 | } 113 | if (setgid(getgid()) == -1) { 114 | /* handle error condition */ 115 | } 116 | 117 | /* It is still possible to regain group privileges due to 118 | * incorrect relinquishment order */ 119 | } 120 | 121 | 122 | /* POS37_C v.29 */ 123 | 124 | void POS37() { 125 | /* Code intended to run with elevated privileges */ 126 | 127 | /* Temporarily drop privileges */ 128 | if (seteuid(getuid()) != 0) { 129 | /* Handle error */ 130 | } 131 | 132 | /* Code intended to run with lower privileges */ 133 | 134 | if (1) { /* need_more_privilege */ 135 | /* Restore privileges */ 136 | if (seteuid(0) != 0) { 137 | /* Handle Error */ 138 | } 139 | 140 | /* Code intended to run with elevated privileges */ 141 | } 142 | 143 | /* ... */ 144 | 145 | /* Permanently drop privileges */ 146 | if (setuid(getuid()) != 0) { 147 | /* Handle Error */ 148 | } 149 | 150 | /* Code intended to run with lower privileges, 151 | but if privilege relinquishment failed, 152 | attacker could regain elevated priveleges! */ 153 | } 154 | -------------------------------------------------------------------------------- /cpp_rules/RES.C: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2007 Carnegie Mellon University. 4 | * All rights reserved. 5 | 6 | * Permission to use this software and its documentation for any purpose is hereby granted, 7 | * provided that the above copyright notice appear and that both that copyright notice and 8 | * this permission notice appear in supporting documentation, and that the name of CMU not 9 | * be used in advertising or publicity pertaining to distribution of the software without 10 | * specific, written prior permission. 11 | * 12 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 13 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 14 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 15 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 16 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "rose.h" 23 | #include "utilities.h" 24 | 25 | bool RES35_C( const SgNode *node ) { // Declare a copy constructor, a copy assignment operator, and a destructor in a class that manages resources 26 | bool ret = false; 27 | if( const SgClassDefinition *cdef = isSgClassDefinition( node ) ) { 28 | // Skip the check if this is a POD (like a C struct). 29 | if( !isPODClass( cdef ) ) { 30 | // First, see which of these three functions the class has. 31 | size_t count = hasExplicitCopyCtor( cdef ) + hasExplicitCopyAssignment( cdef ) + hasExplicitDtor( cdef ); 32 | if( count > 0 && count < 3 ) { 33 | diagnostic( "RES35-C", node, 34 | "if any of copy constructor, copy assignment, and destructor are declared, all three should be." ); 35 | ret = true; 36 | } 37 | //XXX more...how do we know if a class manages resources? Punt and just check for a pointer member? 38 | if( hasPointerMember( cdef ) && count < 3 ) { //XXX should omit this check for unions 39 | diagnostic( "RES35-C", node, 40 | "a class with a pointer data member should probably " 41 | "define a copy constructor, copy assignment, and destructor." ); 42 | ret = true; 43 | } 44 | } 45 | } 46 | return ret; 47 | } 48 | /*========================= 49 | class PrintMember { 50 | public: 51 | void operator ()( const SgNode *node ) const { 52 | if( const SgDeclarationStatement *ds = isSgDeclarationStatement( node ) ) 53 | std::cout << ds->get_mangled_name().getString(); 54 | else 55 | std::cout << "not a declaration statement"; 56 | if( isCompilerGenerated( node ) ) 57 | std::cout << " is compiler-generated."; 58 | std::cout << std::endl; 59 | } 60 | }; 61 | =============================*/ 62 | bool RESMISC_A( const SgNode *node ) { // misc things that haven't found a home yet... 63 | if( const SgClassDefinition *cd = isSgClassDefinition( node ) ) { 64 | std::cout << "==============================" << std::endl; 65 | if( hasCompilerGeneratedDefaultCtor( cd ) ) 66 | std::cout << "\thas compiler generated default ctor" << std::endl; 67 | if( hasTrivialCtor( cd ) ) 68 | std::cout << "\thas trivial ctor" << std::endl; 69 | if( hasTrivialDtor( cd ) ) 70 | std::cout << "\thas trivial dtor" << std::endl; 71 | if( hasCompilerGeneratedDtor( cd ) ) 72 | std::cout << "\thas compiler generated dtor" << std::endl; 73 | if( hasCompilerGeneratedCopyCtor( cd ) ) 74 | std::cout << "\thas compiler generated copy ctor" << std::endl; 75 | if( hasCompilerGeneratedCopyAssignment( cd ) ) 76 | std::cout << "\thas compiler generated copy assign" << std::endl; 77 | if( hasVirtualFunction( cd ) ) 78 | std::cout << "\thas virtual function" << std::endl; 79 | } 80 | return false; 81 | } 82 | 83 | bool RES( SgProject *project ) { 84 | bool violation = false; 85 | Rose_STL_Container nodes = NodeQuery::querySubTree( project, V_SgNode ); 86 | for( Rose_STL_Container::iterator i = nodes.begin(); i != nodes.end(); ++i ) { 87 | violation |= RES35_C( *i ); 88 | //violation |= RESMISC_A( *i ); 89 | } 90 | return violation; 91 | } 92 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.POS.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void POS30(); 17 | void POS33(); 18 | void POS34(); 19 | void POS35(); 20 | void POS36(); 21 | void POS37(); 22 | 23 | void POS() { 24 | POS30(); 25 | POS33(); 26 | POS34(); 27 | POS35(); 28 | POS36(); 29 | POS37(); 30 | } 31 | 32 | 33 | /* POS30_C v.33 */ 34 | 35 | void POS30() { 36 | char buf[1024]; 37 | const ssize_t len = readlink("/usr/bin/perl", buf, sizeof(buf)); 38 | buf[len] = '\0'; 39 | } 40 | 41 | 42 | /* POS33_C v.41 */ 43 | 44 | void POS33() { 45 | const char *filename = "foo"; 46 | 47 | const pid_t pid = vfork(); 48 | if ( pid == 0 ) /* child */ { 49 | if (execve(filename, NULL, NULL) == -1) { 50 | /* Handle Error */ 51 | } 52 | _exit(1); /* in case execve() fails */ 53 | } 54 | } 55 | 56 | 57 | /* POS34_C v.76 */ 58 | 59 | int POS34_func(char const *var) { 60 | char env[1024]; 61 | 62 | if (snprintf(env, sizeof(env),"TEST=%s", var) < 0) { 63 | /* Handle Error */ 64 | } 65 | 66 | return putenv(env); 67 | } 68 | 69 | void POS34() { 70 | int a = POS34_func("hello"); 71 | ++a; 72 | } 73 | 74 | 75 | /* POS35_C v.33 */ 76 | 77 | void POS35() { 78 | const char *filename = "foo"; 79 | char userbuf[] = "foo"; 80 | const unsigned int userlen = sizeof(userbuf); 81 | 82 | struct stat lstat_info; 83 | int fd; 84 | 85 | if (lstat(filename, &lstat_info) == -1) { 86 | /* handle error */ 87 | } 88 | if (!S_ISLNK(lstat_info.st_mode)) { 89 | if ((fd = open(filename, O_RDWR)) == -1) { 90 | /* handle error */ 91 | } 92 | } 93 | if (write(fd, userbuf, userlen) < userlen) { 94 | /* Handle Error */ 95 | } 96 | 97 | close(fd); 98 | } 99 | 100 | 101 | /* POS36_C v.19 */ 102 | 103 | void POS36() { 104 | /* Drop superuser privileges in incorrect order */ 105 | 106 | if (setuid(getuid()) == -1) { 107 | /* handle error condition */ 108 | } 109 | if (setgid(getgid()) == -1) { 110 | /* handle error condition */ 111 | } 112 | 113 | /* It is still possible to regain group privileges due to 114 | * incorrect relinquishment order */ 115 | } 116 | 117 | 118 | /* POS37_C v.29 */ 119 | 120 | void POS37() { 121 | /* Code intended to run with elevated privileges */ 122 | 123 | /* Temporarily drop privileges */ 124 | if (seteuid(getuid()) != 0) { 125 | /* Handle error */ 126 | } 127 | 128 | /* Code intended to run with lower privileges */ 129 | 130 | if (1) { /* need_more_privilege */ 131 | /* Restore privileges */ 132 | if (seteuid(0) != 0) { 133 | /* Handle Error */ 134 | } 135 | 136 | /* Code intended to run with elevated privileges */ 137 | } 138 | 139 | /* ... */ 140 | 141 | /* Permanently drop privileges */ 142 | if (setuid(getuid()) != 0) { 143 | /* Handle Error */ 144 | } 145 | 146 | /* Code intended to run with lower privileges, 147 | but if privilege relinquishment failed, 148 | attacker could regain elevated priveleges! */ 149 | } 150 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.ncce.wiki.SIG.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | #include "cpp.util.h" 16 | 17 | void SIG00(); 18 | void SIG01(); 19 | void SIG30(); 20 | void SIG31(); 21 | void SIG33(); 22 | void SIG34(); 23 | 24 | void SIG() { 25 | SIG00(); 26 | SIG01(); 27 | SIG30(); 28 | SIG31(); 29 | SIG33(); 30 | SIG34(); 31 | } 32 | 33 | volatile sig_atomic_t SIG00_sig1 = 0; 34 | volatile sig_atomic_t SIG00_sig2 = 0; 35 | 36 | void SIG00_handler(int signum) { 37 | if (signum == SIGUSR1) { 38 | SIG00_sig1 = 1; 39 | } 40 | else if (SIG00_sig1) { 41 | SIG00_sig2 = 1; 42 | } 43 | } 44 | 45 | void SIG00() { 46 | if (signal(SIGUSR1, SIG00_handler) == SIG_ERR) { 47 | /* handle error */ 48 | } 49 | if (signal(SIGUSR2, SIG00_handler) == SIG_ERR) { 50 | /* handler error */ 51 | } 52 | 53 | while (SIG00_sig2 == 0) { 54 | /* do nothing or give up CPU for a while */ 55 | } 56 | 57 | /* ... */ 58 | 59 | return; 60 | } 61 | 62 | void SIG01_handler(int signum) { 63 | if (signal(signum, SIG01_handler) == SIG_ERR) { 64 | 65 | } 66 | /* handle signal */ 67 | } 68 | 69 | void SIG01() { 70 | if (signal(SIGUSR1, SIG01_handler) == SIG_ERR) {} 71 | } 72 | 73 | enum { SIG30_MAXLINE = 1024 }; 74 | char *SIG30_info = NULL; 75 | 76 | void SIG30_log_message(void) { 77 | /* something */ 78 | } 79 | 80 | void SIG30_handler(int signum) { 81 | SIG30_log_message(); 82 | free(SIG30_info); 83 | SIG30_info = NULL; 84 | } 85 | 86 | void SIG30(void) { 87 | if (signal(SIGINT, SIG30_handler) == SIG_ERR) {} 88 | SIG30_info = (char*)malloc(SIG30_MAXLINE); 89 | if (SIG30_info == NULL) { 90 | /* Handle Error */ 91 | } 92 | 93 | while (1) { 94 | /* main loop program code */ 95 | 96 | SIG30_log_message(); 97 | 98 | /* more program code */ 99 | } 100 | } 101 | 102 | 103 | char *SIG31_err_msg; 104 | enum { SIG31_MAX_MSG_SIZE = 24 }; 105 | 106 | void SIG31_handler(int signum) { 107 | strcpy(SIG31_err_msg, "SIGINT encountered."); 108 | } 109 | 110 | void SIG31() { 111 | if (signal(SIGINT, SIG31_handler) == SIG_ERR) {} 112 | 113 | SIG31_err_msg = (char *)malloc(SIG31_MAX_MSG_SIZE); 114 | if (SIG31_err_msg == NULL) { 115 | /* handle error condition */ 116 | } 117 | strcpy(SIG31_err_msg, "No errors yet."); 118 | 119 | /* main code loop */ 120 | 121 | return; 122 | } 123 | 124 | void SIG33_log_msg(int signum) { 125 | /* log error message in some asynchronous-safe manner */ 126 | } 127 | 128 | void SIG33_handler(int signum) { 129 | /* do some handling specific to SIGINT */ 130 | if (raise(SIGUSR1)!=0) {} 131 | } 132 | 133 | void SIG33() { 134 | if (signal(SIGUSR1, SIG33_log_msg) != SIG_ERR) {} 135 | if (signal(SIGINT, SIG33_handler) != SIG_ERR) {} 136 | 137 | /* program code */ 138 | if (raise(SIGINT) != 0) {} 139 | /* more code */ 140 | 141 | return; 142 | } 143 | 144 | void SIG34_handler(int signum) { 145 | if (signal(signum, SIG34_handler) == SIG_ERR) {} 146 | /* handle signal */ 147 | } 148 | 149 | void SIG34() { 150 | if (signal(SIGUSR1, SIG34_handler) == SIG_ERR) {} 151 | } 152 | -------------------------------------------------------------------------------- /rosecheckers/test/cpp.cce.wiki.ENV.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | #include "cpp.util.h" 16 | #include 17 | 18 | void ENV00(); 19 | void ENV01(); 20 | void ENV02(); 21 | void ENV03(); 22 | void ENV04(); 23 | void ENV30(); 24 | void ENV31(); 25 | void ENV32(); 26 | 27 | void ENV() { 28 | ENV00(); 29 | ENV01(); 30 | ENV02(); 31 | ENV03(); 32 | ENV04(); 33 | ENV30(); 34 | ENV31(); 35 | ENV32(); 36 | } 37 | 38 | void ENV00(void) { 39 | char *tempvar; 40 | char *temp = getenv("TEMP"); 41 | if (temp != NULL) { 42 | tempvar = (char *)malloc(strlen(temp)+1); 43 | if (tempvar != NULL) { 44 | strcpy(tempvar, temp); 45 | } 46 | else { 47 | /* Handle error */ 48 | return; 49 | } 50 | } 51 | free(tempvar); 52 | tempvar = NULL; 53 | } 54 | 55 | void ENV01(void) { 56 | char *copy = NULL; 57 | const char *temp = getenv("TEST_ENV"); 58 | if (temp != NULL) { 59 | copy = (char *)malloc(strlen(temp) + 1); 60 | if (copy != NULL) { 61 | strcpy(copy, temp); 62 | } 63 | else { 64 | /* Handle error condition */ 65 | } 66 | } 67 | } 68 | 69 | void ENV02(void) { 70 | if (putenv("TEST_ENV=foo") != 0) { 71 | /* Handle error */ 72 | } 73 | if (putenv("OTHER_ENV=bar") != 0) { 74 | /* Handle error */ 75 | } 76 | 77 | const char *temp = getenv("TEST_ENV"); 78 | 79 | if (temp == NULL) { 80 | /* Handle error */ 81 | } 82 | } 83 | 84 | void ENV03(void) { 85 | if (clearenv() != 0) { 86 | /* Handle error */ 87 | return; 88 | } 89 | if (system("ls dir.`date +%Y%m%d`") == -1) { 90 | /* Handle error */ 91 | } 92 | } 93 | 94 | void ENV04(void) { 95 | const char *file_format = "%s/foo"; 96 | size_t len; 97 | char *file; 98 | struct passwd *pwd; 99 | 100 | /* Get /etc/passwd entry for current user */ 101 | pwd = getpwuid(getuid()); 102 | if (pwd == NULL) { 103 | /* Handle error */ 104 | return; 105 | } 106 | 107 | /* build full path name home dir from pw entry */ 108 | 109 | len = strlen(pwd->pw_dir) + strlen(file_format); 110 | file = (char *)malloc(len+1); 111 | snprintf(file, len, file_format, pwd->pw_dir); 112 | if (unlink(file) != 0) { 113 | /* Handle error in unlink */ 114 | } 115 | 116 | free(file); 117 | file = NULL; 118 | } 119 | 120 | void ENV30(void) { 121 | const char *env; 122 | char *copy_of_env; 123 | 124 | env = getenv("TEST_ENV"); 125 | if (env == NULL) { 126 | /* Handle error */ 127 | } 128 | 129 | copy_of_env = new char[strlen(env) + 1]; 130 | strcpy(copy_of_env, env); 131 | } 132 | 133 | void ENV31(void) { 134 | size_t i; 135 | if (setenv("MY_NEW_VAR", "new_value", 1) != 0) { 136 | /* Handle error */ 137 | return; 138 | } 139 | if (environ != NULL) { 140 | for (i = 0; environ[i] != NULL; i++) { 141 | if (puts(environ[i]) == EOF) { 142 | return; 143 | } 144 | 145 | } 146 | } 147 | } 148 | 149 | void ENV32_exit1(void) { 150 | return; 151 | } 152 | 153 | void ENV32(void) { 154 | if (atexit(ENV32_exit1) != 0) { 155 | return; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/categories.C: -------------------------------------------------------------------------------- 1 | /** 2 | * \file categories.C 3 | * 4 | * Copyright (c) 2007 Carnegie Mellon University. 5 | * All rights reserved. 6 | 7 | * Permission to use this software and its documentation for any purpose is 8 | * hereby granted, provided that the above copyright notice appear and that 9 | * both that copyright notice and this permission notice appear in supporting 10 | * documentation, and that the name of CMU not be used in advertising or 11 | * publicity pertaining to distribution of the software without specific, 12 | * written prior permission. 13 | * 14 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 15 | * IMPLIED WSTRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE 16 | * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR 19 | * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include "rose.h" 23 | #include "categories.h" 24 | 25 | const SgBinaryOp *isAnyBinArithOp(const SgNode *node) { 26 | if (isSgAddOp(node) 27 | ||isSgDivideOp(node) 28 | ||isSgModOp(node) 29 | ||isSgSubtractOp(node) 30 | ||isSgMultiplyOp(node) 31 | ||isSgExponentiationOp(node) 32 | ||isSgIntegerDivideOp(node)) { 33 | return isSgBinaryOp(node); 34 | } 35 | return NULL; 36 | } 37 | 38 | const SgBinaryOp *isAnyBinArithAssignOp(const SgNode *node) { 39 | if (isSgPlusAssignOp(node) 40 | ||isSgDivAssignOp(node) 41 | ||isSgModAssignOp(node) 42 | ||isSgMinusAssignOp(node) 43 | ||isSgMultAssignOp(node)) { 44 | return isSgBinaryOp(node); 45 | } 46 | return NULL; 47 | } 48 | 49 | const SgBinaryOp *isAnyBinBitOp(const SgNode *node) { 50 | if (isSgBitAndOp(node) 51 | ||isSgBitOrOp(node) 52 | ||isSgBitXorOp(node) 53 | ||isSgLshiftOp(node) 54 | ||isSgRshiftOp(node)) { 55 | return isSgBinaryOp(node); 56 | } 57 | return NULL; 58 | } 59 | 60 | const SgBinaryOp *isAnyBinBitAssignOp(const SgNode *node) { 61 | if (isSgAndAssignOp(node) 62 | ||isSgIorAssignOp(node) 63 | ||isSgXorAssignOp(node) 64 | ||isSgLshiftAssignOp(node) 65 | ||isSgRshiftAssignOp(node)) { 66 | return isSgBinaryOp(node); 67 | } 68 | return NULL; 69 | } 70 | 71 | const SgBinaryOp *isAnyBinLogicOp(const SgNode *node) { 72 | if (isSgAndOp(node) 73 | ||isSgOrOp(node)) { 74 | return isSgBinaryOp(node); 75 | } 76 | return NULL; 77 | } 78 | 79 | const SgBinaryOp *isAnyAssignOp(const SgNode *node) { 80 | if (isSgAssignOp(node) 81 | ||isAnyBinArithAssignOp(node) 82 | ||isAnyBinBitAssignOp(node) 83 | ||isAnyBinLogicOp(node)) { 84 | return isSgBinaryOp(node); 85 | } 86 | return NULL; 87 | } 88 | 89 | const SgBinaryOp *isAnyEqualityOp(const SgNode *node) { 90 | if (isSgEqualityOp(node) 91 | ||isSgNotEqualOp(node)) { 92 | return isSgBinaryOp(node); 93 | } 94 | return NULL; 95 | } 96 | 97 | const SgBinaryOp *isAnyRelationalOp(const SgNode *node) { 98 | if (isSgGreaterOrEqualOp(node) 99 | ||isSgGreaterThanOp(node) 100 | ||isSgLessOrEqualOp(node) 101 | ||isSgLessThanOp(node)) { 102 | return isSgBinaryOp(node); 103 | } 104 | return NULL; 105 | } 106 | 107 | const SgBinaryOp *isAnyComparisonOp(const SgNode *node) { 108 | if (isAnyEqualityOp(node) 109 | ||isAnyRelationalOp(node)) { 110 | return isSgBinaryOp(node); 111 | } 112 | return NULL; 113 | } 114 | 115 | /** NOT ACCOUNTED FOR 116 | ||isSgConcatenationOp(node) 117 | ||isSgScopeOp(node) 118 | ||isSgArrowExp(node) 119 | ||isSgArrowStarOp(node) 120 | ||isSgCommaOpOp(node) 121 | ||isSgDotExp(node) 122 | ||isSgDotStarOp(node) 123 | ||isSgPntrArrRefExp(node) 124 | */ 125 | 126 | /** 127 | * Checks to see if the type is some kind of char or wchar_t 128 | * 129 | * \note we return false on [un]signed chars since they are numbers not 130 | * characters 131 | */ 132 | bool isAnyCharType(const SgType *type) { 133 | const SgType *t = type->stripTypedefsAndModifiers(); 134 | return isSgTypeChar(t) 135 | || isSgTypeWchar(t) 136 | || isTypeWcharT(type); 137 | } 138 | 139 | bool isAnyPointerType(const SgType *type) { 140 | const SgType *t = type->stripTypedefsAndModifiers(); 141 | return isSgPointerType(t) 142 | || isSgArrayType(t) 143 | || isTypeUintptrT(type); 144 | } 145 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/FLP_NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void FLP02(); 21 | void FLP03(); 22 | void FLP30(); 23 | //void FLP31(); 24 | void FLP32(); 25 | void FLP33(); 26 | void FLP34(); 27 | 28 | void FLP() { 29 | FLP02(); 30 | FLP03(); 31 | FLP30(); 32 | // FLP31(); 33 | FLP32(); 34 | FLP33(); 35 | FLP34(); 36 | } 37 | 38 | 39 | /* FLP02_A v.42 */ 40 | 41 | float FLP02_mean(float array[], int size) { 42 | float total = 0.0; 43 | int i; 44 | for (i = 0; i < size; i++) { 45 | total += array[i]; 46 | printf("array[%d] = %f and total is %f\n", i, array[i], total); 47 | } 48 | if (size != 0) { 49 | return total / size; 50 | } else { 51 | return 0.0; 52 | } 53 | } 54 | 55 | enum {array_size = 10}; 56 | float array_value = 10.1; 57 | 58 | void FLP02(void) { 59 | float array[array_size]; 60 | float avg; 61 | int i; 62 | for (i = 0; i < array_size; i++) { 63 | array[i] = array_value; 64 | } 65 | 66 | avg = FLP02_mean( array, array_size); 67 | printf("mean is %f\n", avg); 68 | if (avg == array[0]) { 69 | printf("array[0] is the mean\n"); 70 | } else { 71 | printf("array[0] is not the mean\n"); 72 | } 73 | } 74 | 75 | /** 76 | * Due to a bug in rose we can't use the pragma in the CCE 77 | */ 78 | // 79 | //void FLP03(void) { 80 | // /* ... */ 81 | // double a = 1e-40, b, c = 0.1; 82 | // float x = 0, y; 83 | // /* inexact and underflows */ 84 | // y = a; 85 | // /* divide by zero operation */ 86 | // b = y / x; 87 | // /* inexact (loss of precision) */ 88 | // c = sin(30) * a; 89 | // /* ... */ 90 | // printf("FLP03 %f %f\n", b, c); 91 | //} 92 | // 93 | void FLP30(void) { 94 | float x; 95 | for (x = 0.1f; x <= 1.0f; x += 0.1f) { 96 | /* ... */ 97 | } 98 | 99 | for (x = 100000001.0f; x <= 100000010.0f; x += 1.0f) { 100 | /* ... */ 101 | } 102 | } 103 | 104 | /* FLP31_A v.15 */ 105 | 106 | //void FLP31(void) { 107 | // double complex c = 2.0 + 4.0 * I; 108 | // /* ... */ 109 | // double complex result = log2(c); 110 | // printf("%f + %fi\n", creal(result), cimag(result)); 111 | //} 112 | 113 | 114 | void FLP32(void) { 115 | const double x = 0; 116 | const double y = 0; 117 | double result; 118 | 119 | result = acos(x); 120 | result = atan2(y, x); 121 | result = pow(x, y); 122 | if (((x == 0.f) && islessequal(y, 0)) || 123 | (isless(x, 0))) { 124 | /* handle domain and range errors */ 125 | } 126 | result = pow(x, y); 127 | result = sqrt(x); 128 | printf("FLP30 %f\n", result); 129 | } 130 | 131 | void FLP33(void) { 132 | const short a = 533; 133 | const int b = 6789; 134 | const long c = 466438237; 135 | 136 | const float d = a / 7; /* d is 76.0 */ 137 | const double e = b / 30; /* e is 226.0 */ 138 | const double f = c * 789; /* f may be negative due to overflow */ 139 | } 140 | 141 | void FLP34(void) { 142 | float f1 = (float)INT_MAX * 2.0; 143 | int i1; 144 | 145 | /* initializations */ 146 | 147 | i1 = (int)f1; /* Undefined if the integral part of f1 > INT_MAX */ 148 | 149 | /* End {code} */ 150 | 151 | /* Begin {code} */ 152 | 153 | const long double ld = 0.0; 154 | const double d1 = 0.0; 155 | double d2 = 0.0; 156 | f1 = 0.0f; 157 | float f2 = 0.0f; 158 | 159 | /* initializations */ 160 | 161 | f1 = (float)d1; 162 | f2 = (float)ld; 163 | d2 = (double)ld; 164 | 165 | /* End {code} */ 166 | printf("FLP34 %f %f %i\n", d2, f2, i1); 167 | } 168 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/ARR_NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void ARR01(); 21 | void ARR02(); 22 | void ARR30(); 23 | //void ARR31(); 24 | void ARR32(); 25 | void ARR33(); 26 | void ARR34(); 27 | //void ARR35(); 28 | void ARR36(); 29 | void ARR37(); 30 | void ARR38(); 31 | 32 | void ARR() { 33 | ARR01(); 34 | ARR02(); 35 | ARR30(); 36 | // ARR31(); 37 | ARR32(); 38 | ARR33(); 39 | ARR34(); 40 | // ARR35(); 41 | ARR36(); 42 | ARR37(); 43 | ARR38(); 44 | } 45 | 46 | /*ARR01_A v.46 */ 47 | 48 | void clear2(int array[]) { 49 | size_t i; 50 | for (i = 0; i < sizeof(array) / sizeof(array[0]); ++i) { 51 | array[i] = 0; 52 | } 53 | } 54 | 55 | void ARR01(void) { 56 | int dis[12]; 57 | 58 | clear2(dis); 59 | /* ... */ 60 | } 61 | 62 | /*ARR02_A v.08 */ 63 | 64 | void ARR02(void) { 65 | /* gcc won't allow this 66 | int ARR02_a[3] = {1, 2, 3, 4}; 67 | */ 68 | } 69 | 70 | /*ARR30_C v.47 */ 71 | 72 | int *table2 = NULL; 73 | 74 | int ARR30_NCCE_insert_in_table(int pos, int value){ 75 | enum { TABLESIZE = 100 }; 76 | if (!table2) { 77 | table2 = (int *)malloc(sizeof(int) * TABLESIZE); 78 | } 79 | if (pos >= TABLESIZE) { 80 | return -1; 81 | } 82 | table2[pos] = value; 83 | return 0; 84 | } 85 | 86 | void ARR30(void) { 87 | if (ARR30_NCCE_insert_in_table(0, 1) == -1) {} 88 | } 89 | 90 | 91 | /*ARR31_C v.53 */ 92 | 93 | /* not implemented */ 94 | 95 | 96 | ///*ARR32_C v.71 */ 97 | //void func(size_t s) { 98 | // int vla[s]; 99 | // /* ... */ 100 | // vla[s-1] = 0; 101 | //} 102 | // 103 | //void ARR32(void) { 104 | //func(50); 105 | //} 106 | 107 | /*ARR33_C v.50 */ 108 | 109 | void ARR33_C(int const src[], size_t len) { 110 | enum { WORKSPACE_SIZE = 256 }; 111 | int dest[WORKSPACE_SIZE]; 112 | memcpy(dest, src, len * sizeof(int)); 113 | /* ... */ 114 | } 115 | 116 | void ARR33(void) { 117 | int lol[32]; 118 | ARR33_C(lol, 15); 119 | } 120 | 121 | /*ARR34_C v.30 */ 122 | 123 | void ARR34(void) { 124 | enum { a = 10, b = 15, c = 20 }; 125 | 126 | int arr1[c][b]; 127 | int (*arr2)[a] = NULL; 128 | /* GCC won't let this by, (the whole purpose of the rule 129 | arr2 = arr1; 130 | */ 131 | printf("ARR34 %p %p\n", arr1, arr2); 132 | } 133 | 134 | /*ARR35_C v.21 */ 135 | 136 | /* No linux solution */ 137 | 138 | /*ARR36_C v.17 */ 139 | 140 | void ARR36(void) { 141 | const int nums[32]; 142 | char *strings[32]; 143 | const int *next_num_ptr = nums; 144 | int free_bytes; 145 | 146 | free_bytes = strings - (char **)next_num_ptr; 147 | printf("ARR36 %d\n", free_bytes); 148 | } 149 | 150 | /*ARR37_C v.22 */ 151 | struct numbers { 152 | int num1; 153 | int num2; 154 | /* ... */ 155 | int num64; 156 | }; 157 | 158 | int sum_numbers2(const struct numbers *numb){ 159 | int total = 0; 160 | int const *numb_ptr; 161 | 162 | for (numb_ptr = &numb->num1; 163 | numb_ptr <= &numb->num64; 164 | numb_ptr++) 165 | { 166 | total += *(numb_ptr); 167 | } 168 | 169 | return total; 170 | } 171 | 172 | void ARR37(void) { 173 | struct numbers my_numbers = { 1, 2, /* ... */ 64 }; 174 | if (sum_numbers2(&my_numbers) < 100) {} 175 | } 176 | 177 | /*ARR38_C v.28 */ 178 | void ARR38(void) { 179 | int ar[20]; 180 | int *ip; 181 | 182 | /* ROSE catches this */ 183 | for (ip = &ar[0]; ip < &ar[21]; ip++) { 184 | *ip = 0; 185 | } 186 | 187 | char *buf = NULL; 188 | size_t len = 1 << 30; 189 | 190 | /* Check for overflow */ 191 | if (buf + len < buf) { 192 | len = -(uintptr_t)buf-1; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /tags/jpcert-080805/c_rules/ncce/ENV_NCCE.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Carnegie Mellon University. 3 | * All rights reserved. 4 | 5 | * Permission to use this software and its documentation for any purpose is hereby granted, 6 | * provided that the above copyright notice appear and that both that copyright notice and 7 | * this permission notice appear in supporting documentation, and that the name of CMU not 8 | * be used in advertising or publicity pertaining to distribution of the software without 9 | * specific, written prior permission. 10 | * 11 | * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 12 | * OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, RISING OUT OF OR IN 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "util.h" 19 | 20 | void ENV00(); 21 | void ENV01(); 22 | void ENV02(); 23 | void ENV03(); 24 | void ENV04(); 25 | void ENV30(); 26 | void ENV31(char const *envp[]); 27 | void ENV32(); 28 | void ENV33(); 29 | 30 | void ENV(char const *envp[]) { 31 | ENV00(); 32 | ENV01(); 33 | ENV02(); 34 | ENV03(); 35 | ENV04(); 36 | ENV30(); 37 | ENV31(envp); 38 | ENV32(); 39 | ENV33(); 40 | } 41 | 42 | 43 | /* ENV00 v.36 */ 44 | 45 | void ENV00() { 46 | const char *tmpvar; 47 | const char *tempvar; 48 | 49 | tmpvar = getenv("TMP"); 50 | if (!tmpvar) return; 51 | tempvar = getenv("TEMP"); 52 | if (!tempvar) return; 53 | 54 | if (strcmp(tmpvar, tempvar) == 0) { 55 | if (puts("TMP and TEMP are the same.\n") == EOF) {} 56 | } 57 | else { 58 | if (puts("TMP and TEMP are NOT the same.\n") == EOF) {} 59 | } 60 | } 61 | 62 | 63 | /* ENV01 v.29 */ 64 | 65 | void ENV01() { 66 | char copy[16]; 67 | const char *temp = getenv("TEST_ENV"); 68 | if (temp != NULL) { 69 | strcpy(copy, temp); 70 | } 71 | } 72 | 73 | 74 | /* ENV02_A v.43 */ 75 | 76 | void ENV02() { 77 | if (putenv("TEST_ENV=foo") != 0) { 78 | /* Handle Error */ 79 | } 80 | if (putenv("Test_ENV=bar") != 0) { 81 | /* Handle Error */ 82 | } 83 | 84 | const char *temp = getenv("TEST_ENV"); 85 | 86 | if (temp == NULL) { 87 | /* Handle Error */ 88 | } 89 | } 90 | 91 | 92 | /* ENV03_A v.62 */ 93 | 94 | void ENV03() { 95 | if (system("/bin/ls dir.`date +%Y%m%d`") != 0) {} 96 | } 97 | 98 | 99 | /* ENV04_A v.65 */ 100 | 101 | void ENV04() { 102 | char *input = NULL; 103 | 104 | /* input gets initialized by user */ 105 | 106 | char cmdbuf[512]; 107 | const int len_wanted = snprintf( 108 | cmdbuf, 109 | sizeof(cmdbuf), 110 | "any_cmd '%s'", 111 | input 112 | ); 113 | if (len_wanted >= sizeof(cmdbuf)) { 114 | perror("Input too long"); 115 | } 116 | else if (len_wanted < 0) { 117 | perror("Encoding error"); 118 | } 119 | else if (system(cmdbuf) == -1) { 120 | perror("Error executing input"); 121 | } 122 | } 123 | 124 | 125 | /* ENV30_C v.41 */ 126 | 127 | void ENV30() { 128 | char *env = getenv("TEST_ENV"); 129 | env[0] = 'a'; 130 | } 131 | 132 | 133 | /* ENV31_C v.43 */ 134 | 135 | void ENV31(char const *envp[]) { 136 | size_t i; 137 | if (setenv("MY_NEW_VAR", "new_value", 1) == -1) {} 138 | if (envp != NULL) { 139 | for (i = 0; envp[i] != NULL; i++) { 140 | if (puts(envp[i]) == EOF) {} 141 | } 142 | } 143 | } 144 | 145 | 146 | /* ENV32_C v.35 */ 147 | 148 | void ENV32_exit1(void) { 149 | /* ...cleanup code... */ 150 | return; 151 | } 152 | 153 | void ENV32_exit2(void) { 154 | if (1) { 155 | /* ...more cleanup code... */ 156 | exit(0); 157 | } 158 | return; 159 | } 160 | 161 | void ENV32() { 162 | if (atexit(ENV32_exit1) != 0) { 163 | /* Handle Error */ 164 | } 165 | if (atexit(ENV32_exit2) != 0) { 166 | /* Handle Error */ 167 | } 168 | /* ...program code... */ 169 | exit(0); 170 | } 171 | 172 | 173 | /* ENV33_C v.25 */ 174 | 175 | jmp_buf ENV33_env; 176 | int ENV33_val; 177 | 178 | void ENV33_exit1(void) { 179 | /* ... */ 180 | longjmp(ENV33_env, 1); 181 | } 182 | 183 | void ENV33(void) { 184 | if (atexit(ENV33_exit1) != 0) { 185 | /* handle error */ 186 | } 187 | /* ... */ 188 | if (setjmp(ENV33_env) == 0) { 189 | exit(0); 190 | } 191 | else { 192 | return; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /rosecheckers/categories.C: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | /** 15 | * \file categories.C 16 | */ 17 | 18 | #include "rose.h" 19 | #include "categories.h" 20 | 21 | const SgBinaryOp *isAnyBinArithOp(const SgNode *node) { 22 | if (isSgAddOp(node) 23 | ||isSgDivideOp(node) 24 | ||isSgModOp(node) 25 | ||isSgSubtractOp(node) 26 | ||isSgMultiplyOp(node) 27 | ||isSgExponentiationOp(node) 28 | ||isSgIntegerDivideOp(node)) { 29 | return isSgBinaryOp(node); 30 | } 31 | return NULL; 32 | } 33 | 34 | const SgBinaryOp *isAnyBinArithAssignOp(const SgNode *node) { 35 | if (isSgPlusAssignOp(node) 36 | ||isSgDivAssignOp(node) 37 | ||isSgModAssignOp(node) 38 | ||isSgMinusAssignOp(node) 39 | ||isSgMultAssignOp(node)) { 40 | return isSgBinaryOp(node); 41 | } 42 | return NULL; 43 | } 44 | 45 | const SgBinaryOp *isAnyBinBitOp(const SgNode *node) { 46 | if (isSgBitAndOp(node) 47 | ||isSgBitOrOp(node) 48 | ||isSgBitXorOp(node) 49 | ||isSgLshiftOp(node) 50 | ||isSgRshiftOp(node)) { 51 | return isSgBinaryOp(node); 52 | } 53 | return NULL; 54 | } 55 | 56 | const SgBinaryOp *isAnyBinBitAssignOp(const SgNode *node) { 57 | if (isSgAndAssignOp(node) 58 | ||isSgIorAssignOp(node) 59 | ||isSgXorAssignOp(node) 60 | ||isSgLshiftAssignOp(node) 61 | ||isSgRshiftAssignOp(node)) { 62 | return isSgBinaryOp(node); 63 | } 64 | return NULL; 65 | } 66 | 67 | const SgBinaryOp *isAnyBinLogicOp(const SgNode *node) { 68 | if (isSgAndOp(node) 69 | ||isSgOrOp(node)) { 70 | return isSgBinaryOp(node); 71 | } 72 | return NULL; 73 | } 74 | 75 | const SgBinaryOp *isAnyAssignOp(const SgNode *node) { 76 | if (isSgAssignOp(node) 77 | ||isAnyBinArithAssignOp(node) 78 | ||isAnyBinBitAssignOp(node) 79 | ||isAnyBinLogicOp(node)) { 80 | return isSgBinaryOp(node); 81 | } 82 | return NULL; 83 | } 84 | 85 | const SgBinaryOp *isAnyEqualityOp(const SgNode *node) { 86 | if (isSgEqualityOp(node) 87 | ||isSgNotEqualOp(node)) { 88 | return isSgBinaryOp(node); 89 | } 90 | return NULL; 91 | } 92 | 93 | const SgBinaryOp *isAnyRelationalOp(const SgNode *node) { 94 | if (isSgGreaterOrEqualOp(node) 95 | ||isSgGreaterThanOp(node) 96 | ||isSgLessOrEqualOp(node) 97 | ||isSgLessThanOp(node)) { 98 | return isSgBinaryOp(node); 99 | } 100 | return NULL; 101 | } 102 | 103 | const SgBinaryOp *isAnyComparisonOp(const SgNode *node) { 104 | if (isAnyEqualityOp(node) 105 | ||isAnyRelationalOp(node)) { 106 | return isSgBinaryOp(node); 107 | } 108 | return NULL; 109 | } 110 | 111 | /** NOT ACCOUNTED FOR 112 | ||isSgConcatenationOp(node) 113 | ||isSgScopeOp(node) 114 | ||isSgArrowExp(node) 115 | ||isSgArrowStarOp(node) 116 | ||isSgCommaOpOp(node) 117 | ||isSgDotExp(node) 118 | ||isSgDotStarOp(node) 119 | ||isSgPntrArrRefExp(node) 120 | */ 121 | 122 | /** 123 | * Checks to see if the type is some kind of char or wchar_t 124 | * 125 | * \note we return false on [un]signed chars since they are numbers not 126 | * characters 127 | */ 128 | bool isAnyCharType(const SgType *type) { 129 | const SgType *t = type->stripTypedefsAndModifiers(); 130 | return isSgTypeChar(t) 131 | || isSgTypeWchar(t) 132 | || isTypeWcharT(type); 133 | } 134 | 135 | bool isAnyPointerType(const SgType *type) { 136 | const SgType *t = type->stripTypedefsAndModifiers(); 137 | return isSgPointerType(t) 138 | || isSgArrayType(t) 139 | || isTypeUintptrT(type); 140 | } 141 | -------------------------------------------------------------------------------- /rosecheckers/test/c.ncce.wiki.FLP.c: -------------------------------------------------------------------------------- 1 | /* 2 | // 3 | // CERT Rosecheckers 4 | // Copyright 2022 Carnegie Mellon University. 5 | // NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN 'AS-IS' BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 6 | // Released under a BSD (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. 7 | // [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. 8 | // CERT(R) is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. 9 | // This Software includes and/or makes use of Additional Software Dependencies, each subject to its own license. 10 | // DM21-0505 11 | // 12 | */ 13 | 14 | #include "util.h" 15 | 16 | void FLP02(); 17 | void FLP03(); 18 | void FLP30(); 19 | //void FLP31(); 20 | void FLP32(); 21 | void FLP33(); 22 | void FLP34(); 23 | 24 | void FLP() { 25 | FLP02(); 26 | FLP03(); 27 | FLP30(); 28 | // FLP31(); 29 | FLP32(); 30 | FLP33(); 31 | FLP34(); 32 | } 33 | 34 | 35 | /* FLP02_A v.42 */ 36 | 37 | float FLP02_mean(float array[], int size) { 38 | float total = 0.0; 39 | int i; 40 | for (i = 0; i < size; i++) { 41 | total += array[i]; 42 | printf("array[%d] = %f and total is %f\n", i, array[i], total); 43 | } 44 | if (size != 0) { 45 | return total / size; 46 | } else { 47 | return 0.0; 48 | } 49 | } 50 | 51 | enum {array_size = 10}; 52 | float array_value = 10.1; 53 | 54 | void FLP02(void) { 55 | float array[array_size]; 56 | float avg; 57 | int i; 58 | for (i = 0; i < array_size; i++) { 59 | array[i] = array_value; 60 | } 61 | 62 | avg = FLP02_mean( array, array_size); 63 | printf("mean is %f\n", avg); 64 | if (avg == array[0]) { 65 | printf("array[0] is the mean\n"); 66 | } else { 67 | printf("array[0] is not the mean\n"); 68 | } 69 | } 70 | 71 | /** 72 | * Due to a bug in rose we can't use the pragma in the CCE 73 | */ 74 | // 75 | //void FLP03(void) { 76 | // /* ... */ 77 | // double a = 1e-40, b, c = 0.1; 78 | // float x = 0, y; 79 | // /* inexact and underflows */ 80 | // y = a; 81 | // /* divide by zero operation */ 82 | // b = y / x; 83 | // /* inexact (loss of precision) */ 84 | // c = sin(30) * a; 85 | // /* ... */ 86 | // printf("FLP03 %f %f\n", b, c); 87 | //} 88 | // 89 | void FLP30(void) { 90 | float x; 91 | for (x = 0.1f; x <= 1.0f; x += 0.1f) { 92 | /* ... */ 93 | } 94 | 95 | for (x = 100000001.0f; x <= 100000010.0f; x += 1.0f) { 96 | /* ... */ 97 | } 98 | } 99 | 100 | /* FLP31_A v.15 */ 101 | 102 | //void FLP31(void) { 103 | // double complex c = 2.0 + 4.0 * I; 104 | // /* ... */ 105 | // double complex result = log2(c); 106 | // printf("%f + %fi\n", creal(result), cimag(result)); 107 | //} 108 | 109 | 110 | void FLP32(void) { 111 | const double x = 0; 112 | const double y = 0; 113 | double result; 114 | 115 | result = acos(x); 116 | result = atan2(y, x); 117 | result = pow(x, y); 118 | if (((x == 0.f) && islessequal(y, 0)) || 119 | (isless(x, 0))) { 120 | /* handle domain and range errors */ 121 | } 122 | result = pow(x, y); 123 | result = sqrt(x); 124 | printf("FLP30 %f\n", result); 125 | } 126 | 127 | void FLP33(void) { 128 | const short a = 533; 129 | const int b = 6789; 130 | const long c = 466438237; 131 | 132 | const float d = a / 7; /* d is 76.0 */ 133 | const double e = b / 30; /* e is 226.0 */ 134 | const double f = c * 789; /* f may be negative due to overflow */ 135 | } 136 | 137 | void FLP34(void) { 138 | float f1 = (float)INT_MAX * 2.0; 139 | int i1; 140 | 141 | /* initializations */ 142 | 143 | i1 = (int)f1; /* Undefined if the integral part of f1 > INT_MAX */ 144 | 145 | /* End {code} */ 146 | 147 | /* Begin {code} */ 148 | 149 | const long double ld = 0.0; 150 | const double d1 = 0.0; 151 | double d2 = 0.0; 152 | f1 = 0.0f; 153 | float f2 = 0.0f; 154 | 155 | /* initializations */ 156 | 157 | f1 = (float)d1; 158 | f2 = (float)ld; 159 | d2 = (double)ld; 160 | 161 | /* End {code} */ 162 | printf("FLP34 %f %f %i\n", d2, f2, i1); 163 | } 164 | --------------------------------------------------------------------------------