[openssh-commits] [openssh] 01/02: upstream: never close stdin

git+noreply at mindrot.org git+noreply at mindrot.org
Wed May 8 14:57:53 AEST 2024


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit bc5dcb8ab9a4e8af54a724883732af378f42ea78
Author: tobias at openbsd.org <tobias at openbsd.org>
AuthorDate: Tue Apr 30 15:40:43 2024 +0000

    upstream: never close stdin
    
    The sanitise_stdfd call makes sure that standard file descriptors are
    open (if they were closed, they are connected with /dev/null).
    
    Do not close stdin in any case to prevent error messages when stdin is
    read multiple times and to prevent later usage of fd 0 for connections,
    e.g.
    
    echo localhost | ssh-keyscan -f - -f -
    
    While at it, make stdin-related error messages nicer.
    
    Authored with Max Kunzelmann <maxdev at posteo dot de>
    
    ok djm
    
    OpenBSD-Commit-ID: 48e9b7938e2fa2f9bd47e6de6df66a31e0b375d3
---
 ssh-keyscan.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index f2e6b59e..ac6551ea 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.155 2024/01/11 01:45:36 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.156 2024/04/30 15:40:43 tobias Exp $ */
 /*
  * Copyright 1995, 1996 by David Mazieres <dm at lcs.mit.edu>.
  *
@@ -854,7 +854,8 @@ main(int argc, char **argv)
 		if (argv[j] == NULL)
 			fp = stdin;
 		else if ((fp = fopen(argv[j], "r")) == NULL)
-			fatal("%s: %s: %s", __progname, argv[j], strerror(errno));
+			fatal("%s: %s: %s", __progname,
+			    fp == stdin ? "<stdin>" : argv[j], strerror(errno));
 
 		while (getline(&line, &linesize, fp) != -1) {
 			/* Chomp off trailing whitespace and comments */
@@ -876,9 +877,11 @@ main(int argc, char **argv)
 		}
 
 		if (ferror(fp))
-			fatal("%s: %s: %s", __progname, argv[j], strerror(errno));
+			fatal("%s: %s: %s", __progname,
+			    fp == stdin ? "<stdin>" : argv[j], strerror(errno));
 
-		fclose(fp);
+		if (fp != stdin)
+			fclose(fp);
 	}
 	free(line);
 

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list