This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][taint] Add isTainted debug expression inspection check
ClosedPublic

Authored by steakhal on Feb 6 2020, 7:51 AM.

Details

Summary

This patch introduces the clang_analyzer_isTainted expression inspection check for checking taint.

Using this we could query the analyzer whether the expression used as the argument is tainted or not.
This would be useful in tests, where we don't want to issue warning for all tainted expressions in a given file (like the debug.TaintTest would do) but only for certain expressions.

Example usage:

int read_integer() {
  int n;
  clang_analyzer_isTainted(n);     // expected-warning{{NO}}
  scanf("%d", &n);
  clang_analyzer_isTainted(n);     // expected-warning{{YES}}
  clang_analyzer_isTainted(n + 2); // expected-warning{{YES}}
  clang_analyzer_isTainted(n > 0); // expected-warning{{YES}}
  return n;
}

Diff Detail

Event Timeline

steakhal created this revision.Feb 6 2020, 7:51 AM

Please add a test as well. Otherwise looks good.

clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
78

I think a comment somewhere why/when do we check only the prefix would be useful.

After tests are added and clang-format-diff.py is ran, this would be an amazing patch, thanks!

steakhal updated this revision to Diff 243144.Feb 7 2020, 5:20 AM
  • Tests added.
  • Clang-format-diff applied.
steakhal updated this revision to Diff 243146.Feb 7 2020, 5:27 AM

Clarified example usage, especially in contrast of eg.: debug.TaintTest checker.

steakhal marked an inline comment as done.Feb 10 2020, 12:13 AM

If this patch is good to go, could someone commit it?
I don't have commit access (yet).

If this patch is good to go, could someone commit it?
I don't have commit access (yet).

I think you can apply for a commit access, you have a history of high quality patches!

clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
78

This isn't done?

427–430

Might as well create a test case for this.

steakhal updated this revision to Diff 246420.Feb 25 2020, 5:21 AM

Declaring the purpose of this checker:

[...]
This would help to reduce the *noise* that the TaintTest debug checker would
introduce and let you focus on the expected-warnings that you really care
about.

Added test to exactly one argument requirement.

steakhal marked 2 inline comments as done.Feb 25 2020, 5:21 AM

Marking comments done.

Szelethus accepted this revision.Mar 2 2020, 6:56 AM

LGTM, thanks! Feel free to commit as you're ready.

clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
78

The documentation shows plenty of other similar debug functions, I think this patch is fine in this regard.

This revision is now accepted and ready to land.Mar 2 2020, 6:56 AM
This revision was automatically updated to reflect the committed changes.
steakhal marked an inline comment as done.