The TaintPropagationRule deduction uses the custom rules from the config.
Check custom sinks when looking for errors. Give an error when at least one of the specified arguments is tainted.
Emit error message and omit a parameter if it's out of bound.
Details
Diff Detail
Event Timeline
In general, don't emit to stderr unless we either emit a warning/error about the incorrect configuration. As an experiment, what happens when you try to emit an error in the middle of the symbolic execution? You can retrieve a DiagnosticsEngine from any decl: D->getASTContext().getDiagnostics() (it's funny how you can retrieve almost all major manager objects if you try hard enough).
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
143 | How about llvm::StringLiteral? | |
820 | Hmmm, how do we do with qualified names (MyClass::generateTaint(), std::cin >>)? |
I think it shouldn't give compile error in case of incorrect configuration now (maybe warning) because:
- Without qualified names, I can create a code which cannot be configured properly.
- It can throw an error without configuration, for example:
void read(int*); // There is an existing propagation rule for it
I suggest to let it unchanged now, and I will change it when the checker can handle qualified names.
On the other hand, I think we should make this type of error configurable (from the command line). So the user can select between warnings and errors.
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
820 | These patches focus on C style functions. I have implemented the uses of qualified names, but I intended to make a separate patch for that. |
I have a few immediate style issues but otherwise it looks good :)
lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
237 ↗ | (On Diff #215268) | StringLiterals need to always be declared as constexpr. |
251 ↗ | (On Diff #215268) | It should be "user-defined" because it's a single adjective. I recommend against using the word "sink" in user-facing messages because it's too jargony. Do we have a better word for this? |
252 ↗ | (On Diff #215268) | This semicolon looks unnecessary. |
595–596 ↗ | (On Diff #215268) | These debug prints should not land. |
840 ↗ | (On Diff #215268) | The GenericTaintChecker:: qualifier is unnecessary. |
Some nits inline, otherwise LGTM. @steakhal, do you have anything to add to this?
lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
191 ↗ | (On Diff #218395) | How about only passing CustomPropagations? |
605 ↗ | (On Diff #218395) | I get that there isn't much substance to this assert, but why remove it? We might as well populate the lines in between that and the branch. |
844 ↗ | (On Diff #218395) | Wasn't this commited before? |
lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
191 ↗ | (On Diff #218395) | I would even consider to move this function out of the whole class. (Not only this function, but the others as well. Like isStdin, etc.) |
844 ↗ | (On Diff #218395) | Yes it was (https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp#L814). |
test/Analysis/taint-generic.c | ||
377 ↗ | (On Diff #218395) | We could use this syntacs to achieve shorter lines. Note that @-1. Same for all the other lines. mySink(x, 1, 2); // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}} |
I'm fine with moving in-class function into anonymous namespace later. LGTM, feel free to commit!
lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
118 ↗ | (On Diff #218395) | Shouldn't we still need an out-of-class initializer part for each static constexpr class member variable? constexpr llvm::StringLiteral GenericTaintChecker::MsgUncontrolledFormatString; constexpr llvm::StringLiteral GenericTaintChecker::MsgSanitizeSystemArgs; constexpr llvm::StringLiteral GenericTaintChecker::MsgTaintedBufferSize; constexpr llvm::StringLiteral GenericTaintChecker::MsgCustomSink; |
Closed by 080ecafdd8b3e990e5ad19202d089c91c9c9b164.
lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | ||
---|---|---|
118 ↗ | (On Diff #218395) | Constexpr values cannot be initialized out of the class, that's why I moved them to here. |
191 ↗ | (On Diff #218395) | I could do that in a separate patch if necessary. |
605 ↗ | (On Diff #218395) | I think there is no need for this. Maybe I can make the ArgNum const. |
251 ↗ | (On Diff #215268) | Currently, I don't have any better idea. I will think about it. |
How about llvm::StringLiteral?