sql_printf_fuzzer.cc 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include "testing/libfuzzer/proto/lpm_interface.h"
  9. #include "third_party/sqlite/fuzz/sql_query_grammar.pb.h"
  10. #include "third_party/sqlite/fuzz/sql_query_proto_to_string.h"
  11. #include "third_party/sqlite/fuzz/sql_run_queries.h"
  12. using namespace sql_query_grammar;
  13. DEFINE_BINARY_PROTO_FUZZER(const Printf& sql_printf) {
  14. std::string printf_str = sql_fuzzer::PrintfToString(sql_printf);
  15. // Convert printf command into runnable SQL query.
  16. printf_str = "SELECT " + printf_str + ";";
  17. if (::getenv("LPM_DUMP_NATIVE_INPUT")) {
  18. std::cout << "_________________________" << std::endl;
  19. std::cout << printf_str << std::endl;
  20. std::cout << "------------------------" << std::endl;
  21. }
  22. std::vector<std::string> queries;
  23. queries.push_back(printf_str);
  24. sql_fuzzer::RunSqlQueries(queries, ::getenv("LPM_SQLITE_TRACE"));
  25. }