github / github/codeql

How can I pick out "Dubious Null Check" by both the caller and the called function (not what DubiousNullCheck.ql means to)?

Aperta
#13,327 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

For example, null check for both the argument `pi` and the parameter `p`:

```cpp
#include

int func(int *p) {
if (p = NULL) return 0;
return *p;
}
int main() {
int i = 9, *pi = &i;
//if (pi != NULL)
printf("%d\n", func(pi));
}
```

I've tried to write some ql, as below, but failed to complete it.
What troubles me the most now is: how to connect the parameter with the argument?

```codeql
import cpp

VariableAccess modify(LocalVariable variable) {
result = variable.getAnAccess() and
result.isModified()
}

from LocalVariable variable, FunctionCall call
where
variable.getType() instanceof PointerType
and exists(call.getTarget().getAParameter())
and call.getEnclosingFunction() = variable.getFunction()
and variable.getAnAccess().getLocation().getStartLine() = call.getLocation().getStartLine()
and not modify(variable).getLocation().getStartLine() = call.getLocation().getStartLine()
and not (call.getTarget().isMember() and call.getTarget().getDeclaringType() = variable.getType().stripType())
select variable, call
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.