https://github.com/aperez created https://github.com/llvm/llvm-project/pull/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. >From d77d6bc22628398c8ae1283740f802d0195261bc Mon Sep 17 00:00:00 2001 From: Alexandre Perez <[email protected]> Date: Wed, 7 Jan 2026 13:33:59 -0800 Subject: [PATCH] [lldb] Fix null pointer dereference in parsed command argument completion --- lldb/source/Commands/CommandObjectCommands.cpp | 3 ++- .../commands/command/script/add/TestAddParsedCommand.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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
