Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Szelethus committed Oct 2, 2023
1 parent 3179c9f commit 5a9ff01
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,229 @@
{"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [{"tool": {"driver": {"name": "GNU C++17", "fullName": "GNU C++17 (Ubuntu 13.1.0-8ubuntu1~22.04) version 13.1.0 (x86_64-linux-gnu)", "version": "13.1.0", "informationUri": "https://gcc.gnu.org/gcc-13/", "rules": [{"id": "-Wanalyzer-double-free", "helpUri": "https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-double-free"}]}}, "taxonomies": [{"name": "CWE", "version": "4.7", "organization": "MITRE", "shortDescription": {"text": "The MITRE Common Weakness Enumeration"}, "taxa": [{"id": "415", "helpUri": "https://cwe.mitre.org/data/definitions/415.html"}]}], "invocations": [{"executionSuccessful": true, "toolExecutionNotifications": []}], "originalUriBaseIds": {"PWD": {"uri": "file:///home/eumakri/Documents/codechecker/tools/report-converter/tests/unit/analyzers/gcc_output_test_files/out/"}}, "artifacts": [{"location": {"uri": "../files/double_free.cpp", "uriBaseId": "PWD"}, "contents": {"text": "// -------------------------------------------------------------------------\n// Part of the CodeChecker project, under the Apache License v2.0 with\n// LLVM Exceptions. See LICENSE for license information.\n// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n// -------------------------------------------------------------------------\n\n#include <stdlib.h>\n\nvoid test() {\n void *ptr = malloc(sizeof(int));\n free(ptr);\n free(ptr);\n}\n"}, "sourceLanguage": "cplusplus"}], "results": [{"ruleId": "-Wanalyzer-double-free", "taxa": [{"id": "415", "toolComponent": {"name": "cwe"}}], "level": "warning", "message": {"text": "double-‘free’ of ‘ptr’"}, "locations": [{"physicalLocation": {"artifactLocation": {"uri": "../files/double_free.cpp", "uriBaseId": "PWD"}, "region": {"startLine": 12, "startColumn": 3, "endColumn": 12}, "contextRegion": {"startLine": 12, "snippet": {"text": " free(ptr);\n"}}}, "logicalLocations": [{"name": "test", "fullyQualifiedName": "test", "decoratedName": "_Z4testv", "kind": "function"}]}], "codeFlows": [{"threadFlows": [{"locations": [{"location": {"physicalLocation": {"artifactLocation": {"uri": "../files/double_free.cpp", "uriBaseId": "PWD"}, "region": {"startLine": 10, "startColumn": 15, "endColumn": 34}, "contextRegion": {"startLine": 10, "snippet": {"text": " void *ptr = malloc(sizeof(int));\n"}}}, "logicalLocations": [{"name": "test", "fullyQualifiedName": "test", "decoratedName": "_Z4testv", "kind": "function"}], "message": {"text": "allocated here"}}, "kinds": ["acquire", "memory"], "nestingLevel": 1}, {"location": {"physicalLocation": {"artifactLocation": {"uri": "../files/double_free.cpp", "uriBaseId": "PWD"}, "region": {"startLine": 11, "startColumn": 3, "endColumn": 12}, "contextRegion": {"startLine": 11, "snippet": {"text": " free(ptr);\n"}}}, "logicalLocations": [{"name": "test", "fullyQualifiedName": "test", "decoratedName": "_Z4testv", "kind": "function"}], "message": {"text": "first ‘free’ here"}}, "kinds": ["release", "memory"], "nestingLevel": 1}, {"location": {"physicalLocation": {"artifactLocation": {"uri": "../files/double_free.cpp", "uriBaseId": "PWD"}, "region": {"startLine": 12, "startColumn": 3, "endColumn": 12}, "contextRegion": {"startLine": 12, "snippet": {"text": " free(ptr);\n"}}}, "logicalLocations": [{"name": "test", "fullyQualifiedName": "test", "decoratedName": "_Z4testv", "kind": "function"}], "message": {"text": "second ‘free’ here; first ‘free’ was at (2)"}}, "kinds": ["danger"], "nestingLevel": 1}]}]}]}]}]}
{
"$schema":"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version":"2.1.0",
"runs":[
{
"tool":{
"driver":{
"name":"GNU C++17",
"fullName":"GNU C++17 (Ubuntu 13.1.0-8ubuntu1~22.04) version 13.1.0 (x86_64-linux-gnu)",
"version":"13.1.0",
"informationUri":"https://gcc.gnu.org/gcc-13/",
"rules":[
{
"id":"-Wanalyzer-double-free",
"helpUri":"https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-double-free"
}
]
}
},
"taxonomies":[
{
"name":"CWE",
"version":"4.7",
"organization":"MITRE",
"shortDescription":{
"text":"The MITRE Common Weakness Enumeration"
},
"taxa":[
{
"id":"415",
"helpUri":"https://cwe.mitre.org/data/definitions/415.html"
}
]
}
],
"invocations":[
{
"executionSuccessful":true,
"toolExecutionNotifications":[

]
}
],
"originalUriBaseIds":{
"PWD":{
"uri":"tests/unit/analyzers/gcc_output_test_files/out/"
}
},
"artifacts":[
{
"location":{
"uri":"../files/double_free.cpp",
"uriBaseId":"PWD"
},
"contents":{
"text":"// -------------------------------------------------------------------------\n// Part of the CodeChecker project, under the Apache License v2.0 with\n// LLVM Exceptions. See LICENSE for license information.\n// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n// -------------------------------------------------------------------------\n\n#include <stdlib.h>\n\nvoid test() {\n void *ptr = malloc(sizeof(int));\n free(ptr);\n free(ptr);\n}\n"
},
"sourceLanguage":"cplusplus"
}
],
"results":[
{
"ruleId":"-Wanalyzer-double-free",
"taxa":[
{
"id":"415",
"toolComponent":{
"name":"cwe"
}
}
],
"level":"warning",
"message":{
"text":"double-‘free’ of ‘ptr’"
},
"locations":[
{
"physicalLocation":{
"artifactLocation":{
"uri":"../files/double_free.cpp",
"uriBaseId":"PWD"
},
"region":{
"startLine":12,
"startColumn":3,
"endColumn":12
},
"contextRegion":{
"startLine":12,
"snippet":{
"text":" free(ptr);\n"
}
}
},
"logicalLocations":[
{
"name":"test",
"fullyQualifiedName":"test",
"decoratedName":"_Z4testv",
"kind":"function"
}
]
}
],
"codeFlows":[
{
"threadFlows":[
{
"locations":[
{
"location":{
"physicalLocation":{
"artifactLocation":{
"uri":"../files/double_free.cpp",
"uriBaseId":"PWD"
},
"region":{
"startLine":10,
"startColumn":15,
"endColumn":34
},
"contextRegion":{
"startLine":10,
"snippet":{
"text":" void *ptr = malloc(sizeof(int));\n"
}
}
},
"logicalLocations":[
{
"name":"test",
"fullyQualifiedName":"test",
"decoratedName":"_Z4testv",
"kind":"function"
}
],
"message":{
"text":"allocated here"
}
},
"kinds":[
"acquire",
"memory"
],
"nestingLevel":1
},
{
"location":{
"physicalLocation":{
"artifactLocation":{
"uri":"../files/double_free.cpp",
"uriBaseId":"PWD"
},
"region":{
"startLine":11,
"startColumn":3,
"endColumn":12
},
"contextRegion":{
"startLine":11,
"snippet":{
"text":" free(ptr);\n"
}
}
},
"logicalLocations":[
{
"name":"test",
"fullyQualifiedName":"test",
"decoratedName":"_Z4testv",
"kind":"function"
}
],
"message":{
"text":"first ‘free’ here"
}
},
"kinds":[
"release",
"memory"
],
"nestingLevel":1
},
{
"location":{
"physicalLocation":{
"artifactLocation":{
"uri":"../files/double_free.cpp",
"uriBaseId":"PWD"
},
"region":{
"startLine":12,
"startColumn":3,
"endColumn":12
},
"contextRegion":{
"startLine":12,
"snippet":{
"text":" free(ptr);\n"
}
}
},
"logicalLocations":[
{
"name":"test",
"fullyQualifiedName":"test",
"decoratedName":"_Z4testv",
"kind":"function"
}
],
"message":{
"text":"second ‘free’ here; first ‘free’ was at (2)"
}
},
"kinds":[
"danger"
],
"nestingLevel":1
}
]
}
]
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class GCCAnalyzerResultTestCase(unittest.TestCase):
""" Test the output of the GccAnalyzerResult. """

def setup_class(self):
""" Setup the test. """
global OLD_PWD
OLD_PWD = os.getcwd()
os.chdir(os.path.join(os.path.dirname(__file__),
'gcc_output_test_files'))
""" Initialize test files. """

global TEST_WORKSPACE
Expand All @@ -54,10 +49,6 @@ def teardown_class(self):
print("Removing: " + TEST_WORKSPACE)
# shutil.rmtree(TEST_WORKSPACE, ignore_errors=True)

""" Restore environment after tests have ran. """
global OLD_PWD
os.chdir(OLD_PWD)

def setUp(self):
""" Setup the test. """
self.analyzer_result = analyzer_result.AnalyzerResult()
Expand Down

0 comments on commit 5a9ff01

Please sign in to comment.