C++: Add a test.

This commit is contained in:
Geoffrey White
2020-06-30 17:43:52 +01:00
parent 54b8f8e662
commit 8bdcc47a50
3 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
void des_function(); // insecure
void function_using_des(); // insecure
void EncryptWithDES(); // insecure
void aes_function(); // secure
void function_using_aes(); // secure
void EncryptionWithAES(); // secure
void abc_function();
void function_using_abc();
void EncryptionWithABC();

View File

@@ -0,0 +1,9 @@
| test.cpp:2:6:2:17 | des_function | getInsecureAlgorithmRegex |
| test.cpp:3:6:3:23 | function_using_des | getInsecureAlgorithmRegex |
| test.cpp:4:6:4:19 | EncryptWithDES | getInsecureAlgorithmRegex |
| test.cpp:6:6:6:17 | aes_function | getSecureAlgorithmRegex |
| test.cpp:7:6:7:23 | function_using_aes | getSecureAlgorithmRegex |
| test.cpp:8:6:8:22 | EncryptionWithAES | getSecureAlgorithmRegex |
| test.cpp:10:6:10:17 | abc_function | |
| test.cpp:11:6:11:23 | function_using_abc | |
| test.cpp:12:6:12:22 | EncryptionWithABC | |

View File

@@ -0,0 +1,14 @@
import default
import semmle.code.cpp.security.Encryption
string describe(Function f) {
f.getName().regexpMatch(getSecureAlgorithmRegex()) and
result = "getSecureAlgorithmRegex"
or
f.getName().regexpMatch(getInsecureAlgorithmRegex()) and
result = "getInsecureAlgorithmRegex"
}
from Function f
where exists(f.getLocation().getFile())
select f, concat(describe(f), ", ")