Sanity check the inputs to SBCommandInterpreter::HandleCompletion

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@145840 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBCommandInterpreter.cpp b/source/API/SBCommandInterpreter.cpp
index 21c19fd..fe514cb 100644
--- a/source/API/SBCommandInterpreter.cpp
+++ b/source/API/SBCommandInterpreter.cpp
@@ -124,6 +124,19 @@
                                         SBStringList &matches)
 {
     int num_completions = 0;
+    
+    // Sanity check the arguments that are passed in:
+    // cursor & last_char have to be within the current_line.
+    if (current_line == NULL || cursor == NULL || last_char == NULL)
+        return 0;
+    
+    if (cursor < current_line || last_char < current_line)
+        return 0;
+        
+    size_t current_line_size = strlen (current_line);
+    if (cursor - current_line > current_line_size || last_char - current_line > current_line_size)
+        return 0;
+        
     if (m_opaque_ptr)
     {
         lldb_private::StringList lldb_matches;