Author: Alexandre Perez Date: 2026-01-08T09:35:02-08:00 New Revision: 3d6a96c0916fb0b238c2fae0e1791d3663415529
URL: https://github.com/llvm/llvm-project/commit/3d6a96c0916fb0b238c2fae0e1791d3663415529 DIFF: https://github.com/llvm/llvm-project/commit/3d6a96c0916fb0b238c2fae0e1791d3663415529.diff LOG: [lldb] Fix null pointer dereference in parsed command completion (#174868) Fix a crash when tab-completing arguments for parsed commands that have arguments but no options. In `HandleArgumentCompletion`, `GetOptions()` returns `nullptr` when a command has no options defined. The code was dereferencing this pointer without a null check, causing a segfault when attempting tab completion. Added: Modified: lldb/source/Commands/CommandObjectCommands.cpp lldb/test/API/commands/command/script/add/TestAddParsedCommand.py Removed: ################################################################################ diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index a3293f0f7966d..70f6955507593 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -2037,7 +2037,8 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed { // option_element_vector: Options *options = GetOptions(); - auto defs = options->GetDefinitions(); + auto defs = options ? options->GetDefinitions() + : llvm::ArrayRef<OptionDefinition>(); std::unordered_set<size_t> option_slots; for (const auto &elem : option_vec) { diff --git a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py index 9deebe29eaae4..da150499a53a2 100644 --- a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py +++ b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py @@ -305,6 +305,13 @@ def cleanup(): matches.AppendList(["answer ", "correct_answer"], 2) self.handle_completion(cmd_str, 1, matches, descriptions, False) + # Test completion for a command with arguments but NO options: + cmd_str = "one-arg-no-opt nonexistent_file_xyz" + matches.Clear() + descriptions.Clear() + matches.AppendString("") + self.handle_completion(cmd_str, 0, matches, descriptions, False) + # Now make sure get_repeat_command works properly: # no-args turns off auto-repeat _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
