bug-hurd
[Top][All Lists]
Advanced

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

[PATCH] libftpconn


From: Moritz Schulte
Subject: [PATCH] libftpconn
Date: Thu, 17 Oct 2002 18:00:14 +0200
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu)

Hi,

some time ago some patches of mine were integrated into
ftpfs/libftpconn.  Those patches fixed a bug, but also broke ftpfs in
a way: I just noticed that

  $ cd foo; cd bar; ls

shows the content of 'foo' while

  $ cd foo; ls; cd bar; ls

shows the content of 'bar'.

The problem, which I introduced with my patches, was that I used
dirname() without keeping in mind that the original path is modified
after using that function.  Here is a patch against libftpconn/unix.c.

2002-10-17  Moritz Schulte  <moritz@duesseldorf.ccc.de>

        * unix.c (ftp_conn_unix_start_get_stats): Call dirname() with
          a copy of name instead of the original name.


--- unix.c      20 Apr 2002 03:22:47 -0000      1.11
+++ unix.c      17 Oct 2002 15:45:39 -0000
@@ -224,14 +224,21 @@
         than looking it up directly, as not all ftp servers support
         the -d option to ls.  To make sure we get a directory, append
         '/', except for the root directory.  */
-      char *dirn = dirname ((char *) name);
-      int is_root = ! strcmp (dirn, "/");
-      req_len += strlen (dirn) + (is_root ? 0 : 1);
-      req = malloc (req_len);
-      if (! req)
-       err = ENOMEM;
+      char *name_cp = strdup ((char *) name);
+      if (name_cp)
+       {
+         char *dirn = dirname (name_cp);
+         int is_root = ! strcmp (dirn, "/");
+         req_len += strlen (dirn) + (is_root ? 0 : 1);
+         req = malloc (req_len);
+         if (! req)
+           err = ENOMEM;
+         else
+           sprintf (req, "%s %s%s", flags, dirn, (is_root ? "" : "/"));
+         free (name_cp);
+       }
       else
-       sprintf (req, "%s %s%s", flags, dirn, (is_root ? "" : "/"));
+       err = ENOMEM;
     }
   else
     {


                moritz
-- 
moritz@duesseldorf.ccc.de - http://duesseldorf.ccc.de/~moritz/
GPG fingerprint = 3A14 3923 15BE FD57 FC06  B501 0841 2D7B 6F98 4199




reply via email to

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