Hello,

I am the maintainer of the lftp port on FreeBSD systems.

First of all, thanks for your great work : lftp is a really nice ftp client :)

Since lftp 3.7.14 (maybe on previous version too, I am not sure), lftp crashes
when entering the 'help' command.

This is due to the funtion print_cmd_index() in commands.cc, where i gets
superior to count and cmd_table[i] is undefined.

Find attached two patches : the first one fixes this error by addind a small
additional check. The second one is a total rewrite of the function, that you
may prefer, being a bit cleaner by avoiding duplicating the code.

Best regards,

Ganaƫl LAPLANCHE
[email protected]
http://www.martymac.com
--- src/commands.cc.orig        2009-07-17 07:05:08.866516763 +0000
+++ src/commands.cc     2009-07-17 07:19:56.249041568 +0000
@@ -2524,26 +2524,21 @@
 void CmdExec::print_cmd_index()
 {
    int i=0;
-   const char *c1;
+   int j=0;
    const cmd_rec *cmd_table=dyn_cmd_table?dyn_cmd_table.get():static_cmd_table;
    const int count=dyn_cmd_table?dyn_cmd_table.count():1024;
    while(i<count && cmd_table[i].name)
    {
       while(cmd_table[i].name && !cmd_table[i].short_desc)
-        i++;
-      if(!cmd_table[i].name)
-        break;
-      c1=cmd_table[i].short_desc;
-      i++;
-      while(cmd_table[i].name && !cmd_table[i].short_desc)
-        i++;
-      if(cmd_table[i].name)
-      {
-        printf("\t%-35s %s\n",gettext(c1),gettext(cmd_table[i].short_desc));
-        i++;
-      }
+            i++;
+      if(i>=count || !cmd_table[i].name)
+            break;
+      if(j%2 == 0)
+         printf("\t%-35s ",gettext(cmd_table[i].short_desc));
       else
-        printf("\t%s\n",_(c1));
+         printf("%s\n",gettext(cmd_table[i].short_desc));
+      i++;
+      j++;
    }
 }
 
--- src/commands.cc.orig        2009-07-17 07:05:08.866516763 +0000
+++ src/commands.cc     2009-07-17 07:06:27.447924317 +0000
@@ -2537,13 +2537,13 @@
       i++;
       while(cmd_table[i].name && !cmd_table[i].short_desc)
         i++;
-      if(cmd_table[i].name)
+      if(i<count && cmd_table[i].name)
       {
         printf("\t%-35s %s\n",gettext(c1),gettext(cmd_table[i].short_desc));
         i++;
       }
       else
-        printf("\t%s\n",_(c1));
+        if(i<count) printf("\t%s\n",_(c1));
    }
 }
 

Reply via email to