Skip to content

Commit ce9c3b4

Browse files
authored
Add CodeQL mismatched dsl_dataset_hold/_rele pairs check
This check is currently limited to checking mismatches that occur in the same stack frame. It does not detect across stack frames. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Signed-off-by: Richard Yao <richard@ryao.dev> Closes #17352
1 parent f70c850 commit ce9c3b4

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

.github/codeql-cpp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ name: "Custom CodeQL Analysis"
22

33
queries:
44
- uses: ./.github/codeql/custom-queries/cpp/deprecatedFunctionUsage.ql
5+
- uses: ./.github/codeql/custom-queries/cpp/dslDatasetHoldReleMismatch.ql
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @name Detect mismatched dsl_dataset_hold/_rele pairs
3+
* @description Flags instances of issue #12014 where
4+
* - a dataset held with dsl_dataset_hold_obj() ends up in dsl_dataset_rele_flags(), or
5+
* - a dataset held with dsl_dataset_hold_obj_flags() ends up in dsl_dataset_rele().
6+
* @kind problem
7+
* @severity error
8+
* @tags correctness
9+
* @id cpp/dslDatasetHoldReleMismatch
10+
*/
11+
12+
import cpp
13+
14+
from Variable ds, Call holdCall, Call releCall, string message
15+
where
16+
ds.getType().toString() = "dsl_dataset_t *" and
17+
holdCall.getASuccessor*() = releCall and
18+
(
19+
(holdCall.getTarget().getName() = "dsl_dataset_hold_obj_flags" and
20+
holdCall.getArgument(4).(AddressOfExpr).getOperand().(VariableAccess).getTarget() = ds and
21+
releCall.getTarget().getName() = "dsl_dataset_rele" and
22+
releCall.getArgument(0).(VariableAccess).getTarget() = ds and
23+
message = "Held with dsl_dataset_hold_obj_flags but released with dsl_dataset_rele")
24+
or
25+
(holdCall.getTarget().getName() = "dsl_dataset_hold_obj" and
26+
holdCall.getArgument(3).(AddressOfExpr).getOperand().(VariableAccess).getTarget() = ds and
27+
releCall.getTarget().getName() = "dsl_dataset_rele_flags" and
28+
releCall.getArgument(0).(VariableAccess).getTarget() = ds and
29+
message = "Held with dsl_dataset_hold_obj but released with dsl_dataset_rele_flags")
30+
)
31+
select releCall,
32+
"Mismatched release: held with $@ but released with " + releCall.getTarget().getName() + " for dataset $@",
33+
holdCall, holdCall.getTarget().getName(),
34+
ds, ds.toString()

0 commit comments

Comments
 (0)