MCPcopy Create free account
hub / github.com/ByConity/ByConity / processWithFuzzing

Method processWithFuzzing

programs/client/Client.cpp:1345–1614  ·  view source on GitHub ↗

Returns false when server is not available.

Source from the content-addressed store, hash-verified

1343
1344 /// Returns false when server is not available.
1345 bool processWithFuzzing(const String & text)
1346 {
1347 ASTPtr orig_ast;
1348
1349 try
1350 {
1351 const char * begin = text.data();
1352 orig_ast = parseQuery(begin, begin + text.size(), true);
1353 }
1354 catch (const Exception & e)
1355 {
1356 if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION)
1357 throw;
1358 }
1359
1360 if (!orig_ast)
1361 {
1362 // Can't continue after a parsing error
1363 return true;
1364 }
1365
1366 // Don't repeat inserts, the tables grow too big. Also don't repeat
1367 // creates because first we run the unmodified query, it will succeed,
1368 // and the subsequent queries will fail. When we run out of fuzzer
1369 // errors, it may be interesting to add fuzzing of create queries that
1370 // wraps columns into LowCardinality or Nullable. Also there are other
1371 // kinds of create queries such as CREATE DICTIONARY, we could fuzz
1372 // them as well. Also there is no point fuzzing DROP queries.
1373 size_t this_query_runs = query_fuzzer_runs;
1374 if (orig_ast->as<ASTInsertQuery>() || orig_ast->as<ASTCreateQuery>() || orig_ast->as<ASTDropQuery>())
1375 {
1376 this_query_runs = 1;
1377 }
1378
1379 ASTPtr fuzz_base = orig_ast;
1380 for (size_t fuzz_step = 0; fuzz_step < this_query_runs; ++fuzz_step)
1381 {
1382 fmt::print(stderr, "Fuzzing step {} out of {}\n", fuzz_step, this_query_runs);
1383
1384 ASTPtr ast_to_process;
1385 try
1386 {
1387 WriteBufferFromOwnString dump_before_fuzz;
1388 fuzz_base->dumpTree(dump_before_fuzz);
1389 auto base_before_fuzz = fuzz_base->formatForErrorMessage();
1390
1391 ast_to_process = fuzz_base->clone();
1392
1393 WriteBufferFromOwnString dump_of_cloned_ast;
1394 ast_to_process->dumpTree(dump_of_cloned_ast);
1395
1396 // Run the original query as well.
1397 if (fuzz_step > 0)
1398 {
1399 fuzzer.fuzzMain(ast_to_process);
1400 }
1401
1402 auto base_after_fuzz = fuzz_base->formatForErrorMessage();

Callers

nothing calls this directly

Calls 15

parseQueryFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
queryHasWithClauseFunction · 0.85
formatForErrorMessageMethod · 0.80
fuzzMainMethod · 0.80
printFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
codeMethod · 0.45
dumpTreeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected