This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Fuzzer] Add command interpreter fuzzer for LLDB
ClosedPublic

Authored by cassanova on Jun 21 2022, 11:17 AM.

Details

Summary

This adds a command interpreter fuzzer to LLDB's fuzzing library. The input data from the fuzzer is used as input for the command interpreter. Input data for the fuzzer is guided by a dictionary of keywords used in LLDB, such as "breakpoint", "target" and others.

Diff Detail

Event Timeline

cassanova created this revision.Jun 21 2022, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 11:17 AM
Herald added a subscriber: mgorny. · View Herald Transcript
cassanova requested review of this revision.Jun 21 2022, 11:17 AM
JDevlieghere added inline comments.Jun 21 2022, 12:53 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/CMakeLists.txt
4

I assume we don't need this anymore if we're using the dummy target?

22

Shouldn't we use an absolute path for the input dictionary? Something like ${CMAKE_CURRENT_SOURCE_DIR}/inputdictionary.txt

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
45

Why do we need a breakpoint?

cassanova added inline comments.Jun 21 2022, 1:11 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/CMakeLists.txt
4

Yes this isn't necessary anymore, I'll remove it and update the revision.

22

Yes an absolute path is better here, I'll add it and update the revision.

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
45

This was a leftover from when I ran this fuzzer with a non-dummy target, removing it doesn't seem to affect the fuzzer so I can take this line out and update the diff.

cassanova updated this revision to Diff 438810.Jun 21 2022, 1:18 PM

Removed ObjectYAML link component from CMakeLists file, changed fuzzer invocation to use a relative path for the dictionary file, removed line that sets a breakpoint in the fuzzer's LLDB process.

JDevlieghere added inline comments.Jun 21 2022, 1:27 PM
lldb/tools/lldb-fuzzer/CMakeLists.txt
2–3

nit: I'd sort these alphabetically

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/CMakeLists.txt
16

I don't think this used any longer.

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
2–3

ASCII art needs fixing :-)

18

Not used?

mib added inline comments.Jun 21 2022, 1:33 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
40

Nit: the variable naming does really follow the lldb's style.

40

doesn't *

cassanova added inline comments.Jun 21 2022, 1:41 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/CMakeLists.txt
16

Ok, I can remove this library.

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
18

Not in this file, but removing that include causes the compiler to not recognize the llvm and lldb_fuzzer namespaces. That's also fine in this file because neither of those namespaces are used but I still found it strange.

40

Oh shoot, I didn't notice. Would interpreter or ci be a better variable name?

mib added inline comments.Jun 21 2022, 1:44 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
40

I was more annoyed by the fact that the variable started with this. It's a reserved keyword in C++ and that can it make error prone. However, ci is a great candidate for this :)

cassanova updated this revision to Diff 438839.Jun 21 2022, 2:41 PM

Sorted subdirectories alphabetically in top-level CMakeLists file.

Removed lldbfuzzer link library in command interpreter CMakeLists file.

Fixed ASCII art in command interpreter source file, renamed thisinterpreter to ci, removed unused include in command interpreter source file.

lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/lldb-commandinterpreter-fuzzer.cpp
40

Ah, good point about that. I renamed it to ci.

cassanova updated this revision to Diff 439021.Jun 22 2022, 7:38 AM

Updated ASCII header to work with 80-column limit.

mib accepted this revision.Jun 22 2022, 10:57 AM

LGTM!

This revision is now accepted and ready to land.Jun 22 2022, 10:57 AM

Updated CMakeLists file to save fuzzer artifacts (the files that the fuzzer writes when an input causes the program being fuzzed to fail) to a directory in the user's build directory, instead of saving them in the user's source directory. Also change fuzzer invocation to add a prefix to artifacts so that it is easier to identify them.

mib added inline comments.Jun 22 2022, 2:00 PM
lldb/tools/lldb-fuzzer/lldb-commandinterpreter-fuzzer/CMakeLists.txt
18

typo

24

You might want to have a top-level fuzzer-artifacts that will have commandinterpreter-fuzzer-artifacts as a subdirectory

cassanova updated this revision to Diff 439158.Jun 22 2022, 2:28 PM

Added a subdirectory to the top-level build directory. This directory will hold directories for the artifacts of various fuzzers. Also corrected a typo in the command interpreter CMakeLists file.

mib accepted this revision.Jun 22 2022, 2:41 PM

Ship it!

This revision was automatically updated to reflect the committed changes.