Prevent wildcards in source specs from matching . or ..
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 30 Nov 2000 21:35:28 +0000 (21:35 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 30 Nov 2000 21:35:28 +0000 (21:35 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@813 cda61777-01e9-0310-a592-d414129be87e

scp.c

diff --git a/scp.c b/scp.c
index 3f85006..a4c0303 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -1003,6 +1003,27 @@ static void toremote(int argc, char *argv[])
        do {
            char *last;
            char namebuf[2048];
+           /*
+            * Ensure that . and .. are never matched by wildcards,
+            * but only by deliberate action.
+            */
+           if (!strcmp(fdat.cFileName, ".") ||
+               !strcmp(fdat.cFileName, "..")) {
+               /*
+                * Find*File has returned a special dir. We require
+                * that _either_ `src' ends in a backslash followed
+                * by that string, _or_ `src' is precisely that
+                * string.
+                */
+               int len = strlen(src), dlen = strlen(fdat.cFileName);
+               if (len == dlen && !strcmp(src, fdat.cFileName)) {
+                   /* ok */;
+               } else if (len > dlen+1 && src[len-dlen-1] == '\\' &&
+                          !strcmp(src+len-dlen, fdat.cFileName)) {
+                   /* ok */;
+               } else
+                   continue;          /* ignore this one */
+           }
            if (strlen(src) + strlen(fdat.cFileName) >=
                sizeof(namebuf)) {
                tell_user(stderr, "%s: Name too long", src);