From 99e407e597e904d4117fad5b351c31f4a0be1f87 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 30 Apr 2024 15:40:44 +0000 Subject: 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 ok djm --- usr.bin/ssh/ssh-keyscan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c index 825220fb178..7fb8c9e339c 100644 --- a/usr.bin/ssh/ssh-keyscan.c +++ b/usr.bin/ssh/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 . * @@ -826,7 +826,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 ? "" : argv[j], strerror(errno)); while (getline(&line, &linesize, fp) != -1) { /* Chomp off trailing whitespace and comments */ @@ -848,9 +849,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 ? "" : argv[j], strerror(errno)); - fclose(fp); + if (fp != stdin) + fclose(fp); } free(line); -- cgit v1.2.3