From 67ff6efc68d0c0596659fc9ac95df21a77ff603b Mon Sep 17 00:00:00 2001 From: shin Date: Mon, 7 Feb 2000 00:52:49 +0000 Subject: [PATCH] Fix telnet core dump at invalid service name specified. Added an error check to avoid it. Approved by: jkh Submitted by: Robert Muir --- contrib/telnet/telnet/commands.c | 6 ++++++ crypto/telnet/telnet/commands.c | 6 ++++++ usr.bin/telnet/commands.c | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/contrib/telnet/telnet/commands.c b/contrib/telnet/telnet/commands.c index 8380c2969bd..bd671f8145d 100644 --- a/contrib/telnet/telnet/commands.c +++ b/contrib/telnet/telnet/commands.c @@ -2475,6 +2475,12 @@ tn(argc, argv) (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1); _hostname[sizeof(_hostname)-1] = '\0'; hostname = _hostname; + } else if (error != 0) { + fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); + if (error == EAI_SYSTEM) + fprintf(stderr, "%s: %s\n", hostname, strerror(errno)); + setuid(getuid()); + return 0; } if (srcroute != 0) { srp = 0; diff --git a/crypto/telnet/telnet/commands.c b/crypto/telnet/telnet/commands.c index 8380c2969bd..bd671f8145d 100644 --- a/crypto/telnet/telnet/commands.c +++ b/crypto/telnet/telnet/commands.c @@ -2475,6 +2475,12 @@ tn(argc, argv) (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1); _hostname[sizeof(_hostname)-1] = '\0'; hostname = _hostname; + } else if (error != 0) { + fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); + if (error == EAI_SYSTEM) + fprintf(stderr, "%s: %s\n", hostname, strerror(errno)); + setuid(getuid()); + return 0; } if (srcroute != 0) { srp = 0; diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 33a45481667..b7e81c4935e 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -2298,6 +2298,12 @@ tn(argc, argv) (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1); _hostname[sizeof(_hostname)-1] = '\0'; hostname = _hostname; + } else if (error != 0) { + fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); + if (error == EAI_SYSTEM) + fprintf(stderr, "%s: %s\n", hostname, strerror(errno)); + setuid(getuid()); + return 0; } if (srcroute != 0) { srp = 0; -- 2.45.2