Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
feliam committed Jul 17, 2022
1 parent 8a79213 commit ecd8adb
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract Test {
event Val(uint, uint);
function f(uint a, uint b) public {
emit Val(a, b);
}
}
contract D {
function bad() public {
Test t = new Test();
address(t).call(abi.encodeWithSelector(Test.f.selector,"test"));
}
function good() public {
Test t = new Test();
address(t).call(abi.encodeWithSelector(Test.f.selector, 1, 2));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
[
[
{
"elements": [
{
"type": "function",
"name": "bad",
"source_mapping": {
"start": 135,
"length": 131,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
8,
9,
10,
11
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "D",
"source_mapping": {
"start": 118,
"length": 286,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad()"
}
},
{
"type": "node",
"name": "address(t).call(abi.encodeWithSelector(Test.f.selector,test))",
"source_mapping": {
"start": 196,
"length": 63,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
10
],
"starting_column": 9,
"ending_column": 72
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad",
"source_mapping": {
"start": 135,
"length": 131,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
8,
9,
10,
11
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "D",
"source_mapping": {
"start": 118,
"length": 286,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad()"
}
}
}
}
],
"description": "D.bad() (tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol#8-11) calls abi.encodeWithSelector() with wrong arguments ataddress(t).call(abi.encodeWithSelector(Test.f.selector,test)) (tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol#10)",
"markdown": "[D.bad()](tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol#L8-L11) calls abi.encodeWithSelector() with wrong arguments at[address(t).call(abi.encodeWithSelector(Test.f.selector,test))](tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol#L10)",
"first_markdown_element": "tests/detectors/wrongencodeselector/0.8.0/wrongencodeselector.sol#L8-L11",
"id": "9230578efcdc63464cf775b07aaf1d04e77ea58363f4809b7f6ffb1dcd46e34f",
"check": "wrongencodeselector",
"impact": "Medium",
"confidence": "High"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
[
[
{
"elements": [
{
"type": "function",
"name": "bad",
"source_mapping": {
"start": 135,
"length": 131,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
8,
9,
10,
11
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "D",
"source_mapping": {
"start": 118,
"length": 286,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad()"
}
},
{
"type": "node",
"name": "address(t).call(abi.encodeWithSelector(Test.f.selector,test))",
"source_mapping": {
"start": 196,
"length": 63,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
10
],
"starting_column": 9,
"ending_column": 72
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "bad",
"source_mapping": {
"start": 135,
"length": 131,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
8,
9,
10,
11
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "D",
"source_mapping": {
"start": 118,
"length": 286,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol",
"is_dependency": false,
"lines": [
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
],
"starting_column": 1,
"ending_column": 2
}
},
"signature": "bad()"
}
}
}
}
],
"description": "D.bad() (tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol#8-11) calls abi.encodeWithSelector() with wrong arguments ataddress(t).call(abi.encodeWithSelector(Test.f.selector,test)) (tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol#10)",
"markdown": "[D.bad()](tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol#L8-L11) calls abi.encodeWithSelector() with wrong arguments at[address(t).call(abi.encodeWithSelector(Test.f.selector,test))](tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol#L10)",
"first_markdown_element": "tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol#L8-L11",
"id": "b47ae579712e33679731aa3f91fdf7221e6a3cfe1b16bfdf1da9d791c6c65ee8",
"check": "wrongencodeselector",
"impact": "Medium",
"confidence": "High"
}
]
]
17 changes: 17 additions & 0 deletions tests/detectors/wrongencodeselector/0.8.15/wrongencodeselector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract Test {
event Val(uint, uint);
function f(uint a, uint b) public {
emit Val(a, b);
}
}
contract D {
function bad() public {
Test t = new Test();
address(t).call(abi.encodeWithSelector(Test.f.selector,"test"));
}
function good() public {
Test t = new Test();
address(t).call(abi.encodeWithSelector(Test.f.selector, 1, 2));
}
}

Loading

0 comments on commit ecd8adb

Please sign in to comment.