From 28bc279cdc6245d5febef9daff2e7653aec9312c Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Tue, 9 May 2017 08:36:35 -0700 Subject: [PATCH] [quandary] tests for passthroughs Summary: Making sure simple passthroughs like the identity function work in C++. Reviewed By: mbouaziz Differential Revision: D5024031 fbshipit-source-id: ce48ead --- .../codetoanalyze/cpp/quandary/basics.cpp | 24 +++++++++++++++++++ .../codetoanalyze/cpp/quandary/issues.exp | 1 + 2 files changed, 25 insertions(+) diff --git a/infer/tests/codetoanalyze/cpp/quandary/basics.cpp b/infer/tests/codetoanalyze/cpp/quandary/basics.cpp index 44c5a0b02..79b148ea4 100644 --- a/infer/tests/codetoanalyze/cpp/quandary/basics.cpp +++ b/infer/tests/codetoanalyze/cpp/quandary/basics.cpp @@ -106,4 +106,28 @@ void via_field_ok2() { obj->field1 = *template_source(); template_sink(obj->field2); } + +template +T* id1(T* t) { + return t; +} + +template +T id2(T t) { + return t; +} + +void via_passthrough_bad1(Obj* obj) { + std::string source = obj->string_source(0); + std::string* source_ptr = &source; + std::string* laundered_source = id1(source_ptr); + obj->string_sink(*laundered_source); +} + +// the summary for id2 doesn't assign to the return value +void FN_via_passthrough_bad2(Obj* obj) { + std::string source = obj->string_source(0); + std::string laundered_source = id2(source); + obj->string_sink(laundered_source); +} } diff --git a/infer/tests/codetoanalyze/cpp/quandary/issues.exp b/infer/tests/codetoanalyze/cpp/quandary/issues.exp index a27beb209..d14c41a29 100644 --- a/infer/tests/codetoanalyze/cpp/quandary/issues.exp +++ b/infer/tests/codetoanalyze/cpp/quandary/issues.exp @@ -8,6 +8,7 @@ codetoanalyze/cpp/quandary/basics.cpp, basics::string_source_bad, 2, QUANDARY_TA codetoanalyze/cpp/quandary/basics.cpp, basics::template_source_bad, 2, QUANDARY_TAINT_ERROR, [return from basics::template_source,call to __infer_taint_sink] codetoanalyze/cpp/quandary/basics.cpp, basics::via_field_bad1, 3, QUANDARY_TAINT_ERROR, [return from basics::template_source_>,call to basics::template_sink_>] codetoanalyze/cpp/quandary/basics.cpp, basics::via_field_bad2, 2, QUANDARY_TAINT_ERROR, [return from basics::template_source_>,call to basics::template_sink_>] +codetoanalyze/cpp/quandary/basics.cpp, basics::via_passthrough_bad1, 4, QUANDARY_TAINT_ERROR, [return from basics::Obj_string_source,flow through basics::id1_>,call to basics::Obj_string_sink] codetoanalyze/cpp/quandary/execs.cpp, execs::callExecBad, 6, QUANDARY_TAINT_ERROR, [return from getenv,call to execl] codetoanalyze/cpp/quandary/execs.cpp, execs::callExecBad, 8, QUANDARY_TAINT_ERROR, [return from getenv,call to execl] codetoanalyze/cpp/quandary/execs.cpp, execs::callExecBad, 11, QUANDARY_TAINT_ERROR, [return from getenv,call to execl]