bug-inetutils
[Top][All Lists]
Advanced

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

Re: A bug in inetutils-20010209 ftp.c


From: Alain Magloire
Subject: Re: A bug in inetutils-20010209 ftp.c
Date: Tue, 27 Feb 2001 11:46:59 -0500 (EST)

Bonjour

> At line 294 of ftp/ftp.c the variable "line" is used as a target of strcpy.
> Unfortunately, the readline() changes cause this to be NULL when processing
> an automatic login via $HOME/.netrc.  This can be reproduced using a .netrc
> similar to the following, and logging into any public ftp site.

Yes.  The assesment is correct.

> ==============================================================
> machine karen
> machine phx
> machine alpha
> machine sparc1
> 
> machine nwlink.com login bde password <my-password>
> macdef init
> passive
> 
> default login ftp password address@hidden
> macdef init
> passive
> 
> ==============================================================
> 
> The following work-around fixes the problem, although the code in question
> should probably use some other variable.  Note that the buffer size was
> 200 in the pre-readline version.

8-) Fair criticisms.  The code flow, is really, really bad.  The dancing
going on with global variables is insane.  Unforunately when readline()
support was add, thing was not cleanup.

> 
> ==============================================================
> --- ftp.c.orig        Fri Jul  7 18:00:53 2000
> +++ ftp.c     Tue Feb 27 00:04:53 2001
> @@ -290,6 +290,8 @@
>               (void) command("ACCT %s", acct);
>       if (proxy)
>               return (1);
> +     free(line);
> +     line = malloc(512);
>       for (n = 0; n < macnum; ++n) {
>               if (!strcmp("init", macros[n].mac_name)) {
>                       (void) strcpy(line, "$init");
> ==============================================================
>
> B. D. Elliott   address@hidden   (Seattle)

Thanks, but you did not guard if HAVE_LIBREADLINE is not set.
Try the patch below and let me know.

Index: ChangeLog
===================================================================
RCS file: /home/cvs/inetutils/ftp/ChangeLog,v
retrieving revision 1.11
diff -c -p -r1.11 ChangeLog
*** ChangeLog   2000/10/30 23:20:37     1.11
--- ChangeLog   2001/02/27 16:52:59
***************
*** 1,3 ****
--- 1,11 ----
+ 2001-02-26  Alain Magloire
+ 
+       * domacro.c : Check if the margv is not NULL and return.
+       * ftp.c (login) : The variable "line" is used as a target of strcpy.
+       Unfortunately, the readline() changes cause this to be NULL when
+       processing an automatic login via $HOME/.netrc.
+       Bug and patch for ftp.c provided by "B. D. Elliott" <address@hidden>. 
+ 
  2000-10-30  Marcus Brinkmann  <address@hidden>
  
        * main.c: Convert to GNU coding standards.
Index: domacro.c
===================================================================
RCS file: /home/cvs/inetutils/ftp/domacro.c,v
retrieving revision 1.4
diff -c -p -r1.4 domacro.c
*** domacro.c   2000/07/06 04:21:07     1.4
--- domacro.c   2001/02/27 16:52:59
*************** TOP:
*** 112,118 ****
--- 112,121 ----
                }
                *cp2 = '\0';
                makeargv();
+               if (margv[0] == NULL)
+                       return;
                c = getcmd(margv[0]);
+               
                if (c == (struct cmd *)-1) {
                        printf("?Ambiguous command\n");
                        code = -1;
Index: ftp.c
===================================================================
RCS file: /home/cvs/inetutils/ftp/ftp.c,v
retrieving revision 1.21
diff -c -p -r1.21 ftp.c
*** ftp.c       2000/07/08 01:00:53     1.21
--- ftp.c       2001/02/27 16:53:02
*************** login(host)
*** 292,297 ****
--- 292,304 ----
                return (1);
        for (n = 0; n < macnum; ++n) {
                if (!strcmp("init", macros[n].mac_name)) {
+ #if HAVE_LIBREADLINE
+                       if (line)
+                               free (line);
+                       line = calloc (200, sizeof (*line));
+                       if (!line)
+                               quit (0, 0);
+ #endif
                        (void) strcpy(line, "$init");
                        makeargv();
                        domacro(margc, margv);






reply via email to

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