Diff

Differences From Artifact [c814f9375b]:

To Artifact [71e8748dec]:


682
683
684
685
686
687
688
689

690
691
692
693





694
695
696
697
698
699
700
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705







-
+




+
+
+
+
+







	return (str);
    else
	return (NULL);
}

/*
 * Return a pointer to the portion of str that comes after the last
 * slash (or backslash, if `local' is TRUE).
 * slash (or backslash or colon, if `local' is TRUE).
 */
static char *stripslashes(char *str, int local)
{
    char *p;

    if (local) {
        p = strchr(str, ':');
        if (p) str = p+1;
    }

    p = strrchr(str, '/');
    if (p) str = p+1;

    if (local) {
	p = strrchr(str, '\\');
	if (p) str = p+1;
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727




1728
1729
1730
1731
1732
1733
1734
1723
1724
1725
1726
1727
1728
1729



1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740







-
-
-
+
+
+
+







	    continue;

	if (targisdir) {
	    /*
	     * Prevent the remote side from maliciously writing to
	     * files outside the target area by sending a filename
	     * containing `../'. In fact, it shouldn't be sending
	     * filenames with any slashes in at all; so we'll find
	     * the last slash or backslash in the filename and use
	     * only the part after that. (And warn!)
	     * filenames with any slashes or colons in at all; so
	     * we'll find the last slash, backslash or colon in the
	     * filename and use only the part after that. (And
	     * warn!)
	     * 
	     * In addition, we also ensure here that if we're
	     * copying a single file and the target is a directory
	     * (common usage: `pscp host:filename .') the remote
	     * can't send us a _different_ file name. We can
	     * distinguish this case because `src' will be non-NULL
	     * and the last component of that will fail to match
1748
1749
1750
1751
1752
1753
1754
1755



1756
1757
1758
1759
1760
1761
1762
1754
1755
1756
1757
1758
1759
1760

1761
1762
1763
1764
1765
1766
1767
1768
1769
1770







-
+
+
+







	     * be trusted).
	     */
	    char *striptarget, *stripsrc;

	    striptarget = stripslashes(act.name, 1);
	    if (striptarget != act.name) {
		tell_user(stderr, "warning: remote host sent a compound"
			  " pathname - possibly malicious! (ignored)");
			  " pathname '%s'", act.name);
		tell_user(stderr, "         renaming local file to '%s'",
                          striptarget);
	    }

	    /*
	     * Also check to see if the target filename is '.' or
	     * '..', or indeed '...' and so on because Windows
	     * appears to interpret those like '..'.
	     */
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1960
1961
1962
1963
1964
1965
1966







1967
1968
1969
1970
1971
1972
1973







-
-
-
-
-
-
-







	/*
	 * Trim off the last pathname component of `src', to
	 * provide the base pathname which will be prepended to
	 * filenames returned from Find{First,Next}File.
	 */
	srcpath = dupstr(src);
	last = stripslashes(srcpath, 1);
	if (last == srcpath) {
	    last = strchr(srcpath, ':');
	    if (last)
		last++;
	    else
		last = srcpath;
	}
	*last = '\0';

	dir = FindFirstFile(src, &fdat);
	if (dir == INVALID_HANDLE_VALUE) {
	    run_err("%s: No such file or directory", src);
	    continue;
	}