We weren't correctly discounting "." and ".." when they came from
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sat, 26 Feb 2005 00:41:36 +0000 (00:41 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sat, 26 Feb 2005 00:41:36 +0000 (00:41 +0000)
FindFirstFile(), with hilarious consequences for recursive transfers in
PSFTP. (PSCP appears to behave fine; it does its own "."/".." removal.)

git-svn-id: svn://svn.tartarus.org/sgt/putty@5398 cda61777-01e9-0310-a592-d414129be87e

windows/winsftp.c

index 82bea80..ff471dd 100644 (file)
@@ -306,20 +306,26 @@ DirHandle *open_directory(char *name)
 
 char *read_filename(DirHandle *dir)
 {
-    while (!dir->name) {
-       WIN32_FIND_DATA fdat;
-       int ok = FindNextFile(dir->h, &fdat);
+    do {
 
-       if (!ok)
-           return NULL;
+       if (!dir->name) {
+           WIN32_FIND_DATA fdat;
+           int ok = FindNextFile(dir->h, &fdat);
+           if (!ok)
+               return NULL;
+           else
+               dir->name = dupstr(fdat.cFileName);
+       }
 
-       if (fdat.cFileName[0] == '.' &&
-           (fdat.cFileName[1] == '\0' ||
-            (fdat.cFileName[1] == '.' && fdat.cFileName[2] == '\0')))
+       assert(dir->name);
+       if (dir->name[0] == '.' &&
+           (dir->name[1] == '\0' ||
+            (dir->name[1] == '.' && dir->name[2] == '\0'))) {
+           sfree(dir->name);
            dir->name = NULL;
-       else
-           dir->name = dupstr(fdat.cFileName);
-    }
+       }
+
+    } while (!dir->name);
 
     if (dir->name) {
        char *ret = dir->name;