Mailing List Archive

Portable OpenSSH on Linux: confusing error message with scp
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,
--
Leah Neukirchen <leah@vuxu.org> https://leahneukirchen.org/
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Portable OpenSSH on Linux: confusing error message with scp [ In reply to ]
On Tue, 5 Apr 2022, Leah Neukirchen wrote:

> 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;
> }

> would be a suitable override, or perhaps you have a better idea.

Without looking at the code (asking the Linux kernel developers to
fix their errno… probably doesn’t have a chance), maybe:

nexists = stat(np, &stb) ? errno : 0;
/*…*/
if (nexists ||
(ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) {
run_err("%s: %s", np,
strerror(nexists ? nexists : errno));
continue;
}
(and do something about that bad label)

Or even:
if (!(exists = stat(np, &stb) == 0))
goto bad;
/*… rest as above */
But only if that elided stuff isn’t important. If it is, maybe:

nexists = stat(np, &stb) ? errno : 0;
/*…*/
if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) {
run_err("%s: %s", np,
strerror(nexists ? nexists : errno));
continue;
}

Just a shoot into the blue that came to me while reading the mail.

bye,
//mirabilos
--
Sometimes they [people] care too much: pretty printers [and syntax highligh-
ting, d.A.] mechanically produce pretty output that accentuates irrelevant
detail in the program, which is as sensible as putting all the prepositions
in English text in bold font. -- Rob Pike in "Notes on Programming in C"
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Portable OpenSSH on Linux: confusing error message with scp [ In reply to ]
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.

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev