Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Blame | Last modification | View Log | RSS feed

Author: Magnus Holmgren
Description: Avoid crashing when tab-completing an empty command line in lsftp
 The problem was that lsftp_s_skip returns NULL if nothing but
 separator characters are found, and that case wasn't handled.

--- a/src/sftp/rl.c
+++ b/src/sftp/rl.c
@@ -205,7 +205,7 @@ int char_quoted( char* text, int index )
 char** lsftp_rl_completion(char* text, int start, int end)
 {
   char** matches=NULL;
-  int s;
+  const char *s;
 
   /* If this word is at the start of the line, then it is a command to
    * complete.
@@ -213,9 +213,9 @@ char** lsftp_rl_completion(char* text, i
 
   rl_completion_append_character = ' '; /* Trailing space after word */
 
-  s = lsftp_s_skip( rl_line_buffer, " \n\t\r" ) - rl_line_buffer;
+  s = lsftp_s_skip( rl_line_buffer, " \n\t\r" );
 
-  if ( start == s ) /* The first word should be a command, even with spaces in front */
+  if ( !s || rl_line_buffer + start == s ) /* The first word should be a command, even with spaces in front */
     {
       matches = RL_COMPLETION_MATCHES(
                                      text,
@@ -231,7 +231,7 @@ char** lsftp_rl_completion(char* text, i
 
       /* Get the first word from the line (the command) */
 
-      lsftp_s_strtok( rl_line_buffer+s," \n\t\r", &tmp );
+      lsftp_s_strtok( s," \n\t\r", &tmp );
 
       while( (cmdname = commands[i].name) )
        {