Portable OpenSSH on Linux: confusing error message with scp

Jakub Jelen jjelen at redhat.com
Thu Apr 7 19:47:12 AEST 2022


On 4/5/22 22:14, Leah Neukirchen wrote:
> Hi,
> 
> With OpenSSH 8.9p1 (and earlier) and scp server-side on Linux 5.13,
> one gets a very confusing error message when the target directory ends
> with / and *does not exist*:
> 
> 	% scp /etc/issue localhost:/usr/foobar/
> 	scp: /usr/foobar/: Is a directory
> 
> stracing shows:
> 
> [pid 32671] stat("/usr/foobar/", 0x7fff4aaa5fd0) = -1 ENOENT (No such file or directory)
> [pid 32671] openat(AT_FDCWD, "/usr/foobar/", O_WRONLY|O_CREAT, 0644) = -1 EISDIR (Is a directory)
> 
> scp.c does rougly:
> 
>                  exists = stat(np, &stb) == 0;
>                  /* ... stuff elided ... */
>                  if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) {
> bad:                    run_err("%s: %s", np, strerror(errno));
>                          continue;
>                  }
> 
> open(2) says:
> 
>         EISDIR pathname refers to a directory and the access requested involved
>                writing (that is, O_WRONLY or O_RDWR is set).
> 
> Apparently, on OpenBSD it prints "No such file or directory" instead.
> 
> I wonder if adding
> 
> 		if (errno == EISDIR)
> 			errno = ENOENT;
> 
> would be a suitable override, or perhaps you have a better idea.
> But printing something is directory when it isn't is confusing. :)
> 
> cu,

This was first reported in 2010 as far as I know and it was one of the 
first issues I was trying to fix in OpenSSH:

https://bugzilla.mindrot.org/show_bug.cgi?id=1768

Unfortunately, without any answer from the OpenSSH developers for almost 
12 years. From time to time, somebody runs into this issue, complains 
but nothing really changed.

Hope it helps,
-- 
Jakub Jelen
Crypto Team, Security Engineering
Red Hat, Inc.



More information about the openssh-unix-dev mailing list