port of: From f2aa49e7fda515163da188ec75dba223e2e52216 Mon Sep 17 00:00:00 2001 From: Brooks Davis <brooks@FreeBSD.org> Date: Mon, 26 Sep 2022 18:56:51 +0100 Subject: telnetd: fix two-byte input crash Move initialization of the slc table earlier so it doesn't get accessed before that happens. For details on the issue, see: https://pierrekim.github.io/blog/2022-08-24-2-byte-dos-freebsd-netbsd-telnetd-netkit-telnetd-inetutils-telnetd-kerberos-telnetd.html Reviewed by: cy Obtained from: NetBSD via cy Differential Revision: https://reviews.freebsd.org/D36680 (cherry picked from commit 6914ffef4e2318ca1d0ead28eafb6f06055ce0f8) --- contrib/telnet/telnetd/telnetd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/telnet/telnetd/telnetd.c b/contrib/telnet/telnetd/telnetd.c index 522877829735..e12fe70997ab 100644 --- a/contrib/telnet/telnetd/telnetd.c +++ b/contrib/telnet/telnetd/telnetd.c @@ -647,6 +647,11 @@ doit(struct sockaddr *who, socklen_t who char user_name[256]; /* + * Initialize the slc mapping table. + */ + get_slc_defaults(); + + /* * Find an available pty to use. */ pty = getpty(); @@ -757,10 +762,6 @@ void telnet(int f, int p) const char *IM; int pty_read_ok = 0; /* track whether the pty read has worked yet */ - /* - * Initialize the slc mapping table. - */ - get_slc_defaults(); CHECK_CLEANUP; /* -- cgit v1.2.3