ci: rework fuzzer script

This commit is contained in:
Amaan Qureshi 2023-07-19 22:20:01 -04:00
parent 3f44b89685
commit f9e5696bcb
No known key found for this signature in database
GPG key ID: E67890ADC4227273
4 changed files with 29 additions and 48 deletions

View file

@ -47,7 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
TSTree *tree = ts_parser_parse_string(parser, NULL, str, size);
TSNode root_node = ts_tree_root_node(tree);
if (lang_query) {
if (lang_query != nullptr) {
{
TSQueryCursor *cursor = ts_query_cursor_new();

View file

@ -1,31 +0,0 @@
import json
import sys
def find_literals(literals, node):
'''Recursively find STRING literals in the grammar definition'''
if type(node) is dict:
if 'type' in node and node['type'] == 'STRING' and 'value' in node:
literals.add(node['value'])
for key, value in node.iteritems():
find_literals(literals, value)
elif type(node) is list:
for item in node:
find_literals(literals, item)
def main():
'''Generate a libFuzzer / AFL dictionary from a tree-sitter grammar.json'''
with open(sys.argv[1]) as f:
grammar = json.load(f)
literals = set()
find_literals(literals, grammar['rules'])
for lit in sorted(literals):
if lit:
print '"%s"' % ''.join(['\\x%02x' % ord(b) for b in lit.encode('utf-8')])
if __name__ == '__main__':
main()