bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-inetutils] ftp 1.5 open - arguments too long?


From: Barry deFreese
Subject: Re: [bug-inetutils] ftp 1.5 open - arguments too long?
Date: Tue, 27 Mar 2007 23:56:21 -0400
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Barry deFreese wrote:


Alfred M. Szmidt wrote:
<snip>
  This is incorrect.  It will change the prompt for all callers for
another().  And you only change the caller at one place, for the
`(to)' prompt.  You should use sprintf and make a new string that
looks like it should in the HAVE_READLINE case.
Is this any better? It still segfaults for me though after connecting to the host.. :-(

Barry

OK, third time is a charm. What was happening was the free (line); in main.c: cmdscanner () was puking. I'm a little surprised that this wasn't an issue before. The only thing I can think of is that we weren't frobbing line with readline previously (in cmds.c). Of course my other concern now is that I have some type of memory leak but everything seems to work fine and I'm not sure that free'ing line made any sense anyway.

Let me know what you think.

Thanks,

Barry deFreese (aka bddebian)


diff -urN inetutils-20070322/ftp/cmds.c 
ftp_readline/inetutils-20070322/ftp/cmds.c
--- inetutils-20070322/ftp/cmds.c       2007-03-21 21:44:58.000000000 -0400
+++ ftp_readline/inetutils-20070322/ftp/cmds.c  2007-03-27 18:30:28.000000000 
-0400
@@ -69,6 +69,10 @@
    system headers on some platforms. */
 #include <glob.h>
 
+#if HAVE_READLINE_READLINE_H
+# include <readline/readline.h>
+#endif
+
 #include "ftp_var.h"
 
 /* Returns true if STR is entirely lower case.  */
@@ -136,20 +140,48 @@
      char ***pargv;
      char *prompt;
 {
-  int len = strlen (line), ret;
+  int ret, len;
+
+#if HAVE_LIBREADLINE
+  char *l;
+
+/* Add brackets () and space to prompt */
+       char *newprmpt = xmalloc (strlen (prompt) + strlen ("() "));
+  sprintf (newprmpt, "(%s) ", prompt);
+  l = readline (newprmpt);
+  if (!l)
+    quit(0, 0);
+
+  line = strcat (line, " ");
+  line = strcat (line, l);
+
+       if (l)
+    free (l);
+
+  if (newprmpt)
+    free (newprmpt);
+
+  if (line && *line)
+    add_history (line);
+
+  len = strlen (line);
+#else
+  len = strlen (line);
 
   if (len >= sizeof (line) - 3)
     {
       printf ("sorry, arguments too long\n");
       intr ();
     }
-  printf ("(%s) ", prompt);
+  printf ("%s", prompt);
   line[len++] = ' ';
   if (fgets (&line[len], sizeof (line) - len, stdin) == NULL)
     intr ();
   len += strlen (&line[len]);
   if (len > 0 && line[len - 1] == '\n')
     line[len - 1] = '\0';
+#endif
+
   makeargv ();
   ret = margc > *pargc;
   *pargc = margc;
diff -urN inetutils-20070322/ftp/main.c 
ftp_readline/inetutils-20070322/ftp/main.c
--- inetutils-20070322/ftp/main.c       2007-03-21 17:46:39.000000000 -0400
+++ ftp_readline/inetutils-20070322/ftp/main.c  2007-03-27 23:46:29.000000000 
-0400
@@ -309,10 +309,8 @@
 
 #if HAVE_LIBREADLINE
       if (line)
-       {
-         free (line);
-         line = 0;
-       }
+         line = 0;
+
       line = readline (prompt);
       if (!line)
        quit (0, 0);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]