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 
5 #include <cstdlib>
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
10 #include "testing/libfuzzer/proto/lpm_interface.h"
11 #include "third_party/sqlite/fuzz/sql_query_grammar.pb.h"
12 #include "third_party/sqlite/fuzz/sql_query_proto_to_string.h"
13 #include "third_party/sqlite/fuzz/sql_run_queries.h"
14 
15 using namespace sql_query_grammar;
16 
DEFINE_BINARY_PROTO_FUZZER(const Expr & expr)17 DEFINE_BINARY_PROTO_FUZZER(const Expr& expr) {
18   std::string expr_str = sql_fuzzer::ExprToString(expr);
19   // Convert printf command into runnable SQL query.
20   expr_str = "SELECT " + expr_str + ";";
21 
22   if (::getenv("LPM_DUMP_NATIVE_INPUT")) {
23     std::cout << "_________________________" << std::endl;
24     std::cout << expr_str << std::endl;
25     std::cout << "------------------------" << std::endl;
26   }
27 
28   std::vector<std::string> queries;
29   queries.push_back(expr_str);
30   sql_fuzzer::RunSqlQueries(queries, ::getenv("LPM_SQLITE_TRACE"));
31 }
32