Commit Graph

181 Commits

Author SHA1 Message Date
Dimitry Andric
c794d18822 Fix snprintf truncation in telnet
Building telnet with clang 18 results in the following warning:

  contrib/telnet/telnet/telnet.c:231:5: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 11 [-Werror,-Wformat-truncation]
    231 |     snprintf(temp2, sizeof(temp2), "%c%c%c%c....%c%c", IAC, SB, TELOPT_COMPORT,
	|     ^

The temp2 buffer is 10 chars, while the format string also consists of
10 chars. Therefore, snprintf(3) will truncate the last character, 'SE'
(end sub negotation) in this case.

Bump the buffer to 11 chars to avoid truncation.

MFC after:	3 days
2023-12-21 23:45:52 +01:00
Brooks Davis
a3c858005c telnet: remove locally added __FBSDID
This partially reverts 77b7cdf199.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42704
2023-11-27 16:47:37 +00:00
John Baldwin
11af9d2477 telnet: Use C89 function definitions for two stragglers.
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D39528
2023-04-18 11:27:47 -07:00
Gordon Bergling
d2e0204ec0 telnet.1: Fix a typo in the manual page
- s/addreess/address/

MFC after:	3 days
2023-04-11 10:42:37 +02:00
Brooks Davis
d701f45aba Remove telnetd sources
Differential Revision:	https://reviews.freebsd.org/D36621
2022-10-05 17:27:14 +01:00
Dag-Erling Smørgrav
0aa2700123 Put OPIE to rest.
Differential Revision: https://reviews.freebsd.org/D36592
2022-10-02 03:37:29 +02:00
Brooks Davis
b4cfdbfed2 manpages: Remove telnetd references
Mostly remove from the SEE ALSO section, adding a mention of the port
where not removed. Elsewhere, remove as appropriate and change from .Xr
to .Nm where a mention of telnetd continues to make sense (or removing
it would require significant reworking of the surrounding text).

Reviewed by:	imp, delphij, emaste
Differential Revision:	https://reviews.freebsd.org/D36785
2022-09-29 17:56:41 +01:00
Cy Schubert
5760cb266e Fix CVE-2020-10188
Reviewed by:		emaste
Obtained from:		NetBSD 6cc1539c8028b
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D36732
2022-09-27 10:36:13 -07:00
Brooks Davis
6914ffef4e 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
2022-09-26 18:57:18 +01:00
Brooks Davis
24e1824e46 Deprecate telnet daemon
The telnetd codebase is old, unmaintained, and has a number of quality
issues.  Users wishing to provide telnetd service should find a
maintained implementation.  The telnet client is NOT deprecated as it
is lower risk.

Reviewed by:	pauamma, kevans, kp, melifaro
MFC After:	3 days
Differential Revision:	https://reviews.freebsd.org/D36619
2022-09-21 16:17:04 +01:00
Cy Schubert
a7399ea2dd telnet: Fix telnet segfault when invalid set or help help commands
Silently ignore invalid set ' ' and invalid help help commands.
This is the same fix applied by NetBSD in hg commit 1019940:4f248823eaff.

PR:		265097
Reported by:	Simon Josefsson <simon@josefsson.org>
Obtained from:	NetBSD hg commit 1019940:4f248823eaff
		NetBSD PR/56918
MFC after:	1 week
2022-07-15 06:38:57 -07:00
Edward Tomasz Napierala
224c772ca5 telnet(1): add quiet mode ("telnet -Q")
Reviewed By:	imp, phk
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
X-NetApp-PR:	#54
Differential Revision:	https://reviews.freebsd.org/D30819
2021-06-21 17:11:57 +01:00
Poul-Henning Kamp
3db1b221ed Set stdout & stderr unbuffered, so that the "telnet>" prompt
also shows up when output is redirected:

	telnet |& tee _log
2020-12-29 21:05:48 +00:00
Gordon Bergling
4310fb0cef telnet(1): Document -P option
PR:		248157
Submitted by:	Juraj Lutter <juraj at lutter dot sk>
Reviewed by:	bcr
Approved by:	bcr
Obtained from:	NetBSD
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25794
2020-08-07 08:41:14 +00:00
Kyle Evans
103d3266eb telnet: kill off remaining duplicate definition 2020-03-28 20:43:15 +00:00
Kyle Evans
fb1bc03eee Re-apply r359399: telnet -fno-common fix
line and auth_level's redefinitions are just extraneous

telnetd will #define extern and then include ext.h to allocate storage for
all of these extern'd vars; however, two of them are actually defined in
libtelnet instead. Instead of doing an #ifdef extern dance around those
function pointers, just add an EXTERN macro to make it easier to
differentiate by sight which ones will get allocated in globals.c and which
ones are defined elsewhere.

MFC after:	3 days
2020-03-28 19:43:45 +00:00
Kyle Evans
42b4e3fb5e Revert 359399: telnet -fno-common bits
There was a large misfire from my local diff that I need to investigate, and
this version committed did not build.
2020-03-28 17:57:36 +00:00
Kyle Evans
c1b2af731b telnet: remove some duplicate definitions, mark terminaltype extern
Most of these were already properly declared and defined elsewhere, this is
effectively just a minor cleanup that fixes the -fno-common build.

-fno-common will become the default in GCC10/LLVM11.

MFC after:	3 days
2020-03-28 17:06:34 +00:00
Conrad Meyer
23c30549af libtelnet: Replace bogus use of srandomdev + random to generate "public key pair"
I'm pretty skeptical that any crypto in telnet is worth using, but if we're
ostensibly generating keys, arc4random is strictly better than the previous
construct.
2019-12-13 05:42:57 +00:00
Ed Maste
83129c0b65 telnet: remove 3rd clause from Berkeley copyrights
Per the July 22, 1999 letter (in /COPYRIGHT) from
William Hoskins
Director, Office of Technology Licensing
University of California, Berkeley

MFC after:	1 week
2019-08-15 13:27:57 +00:00
Ed Maste
deffed6ea2 telnet: use asprintf for r349890 change
Suggested by:	imp
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
2019-08-01 13:46:04 +00:00
Philip Paeps
6071f00ffe telnet: fix minor style violation
While here also fix a very unlikely NULL pointer dereference.

Submitted by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2019-07-10 22:36:14 +00:00
Philip Paeps
e68ce1cc10 telnet: fix a couple of snprintf() buffer overflows
Obtained from:	Juniper Networks
MFC after:	1 week
2019-07-10 17:42:04 +00:00
Jung-uk Kim
b285c5df3a Make telnet(1) buildable. 2018-09-19 07:01:22 +00:00
Jung-uk Kim
3459507c9d Revert r338774. Unrelated changes were committed with Apache Serf. 2018-09-19 06:56:37 +00:00
Jung-uk Kim
3d32dc633c Update Apache Serf to 1.3.9 to make it buildable with OpenSSL 1.1.1. 2018-09-19 06:49:55 +00:00
Conrad Meyer
2c710c67d4 telnetd(8): Fix dereference of uninitialized value 'IF'
Reported by:	Coverity
Sponsored by:	Dell EMC Isilon
2018-03-16 20:59:56 +00:00
Stephen J. Kiernan
3fab177f90 Fix memory leak in edithost
The problem is that when the parameter 'pat' is null, the function locally
allocates a NULL string but never frees it.

Instead of tracking the local alloc, it is noted that the while(*pat) never
enters when there is a local alloc.
So instead of doing the local alloc, check that 'pat' is null before the
while(*pat) loop.

Found using clang's static analyzer - scan-build

Submitted by:	Thomas Rix <trix@juniper.net>
Reviewed by:	markm
Approved by:	sjg (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D9689
2017-06-01 19:21:30 +00:00
Gleb Smirnoff
f5c44977ff When telnetd(8) composes argument list for login(1), an unexpected sequence
of memory allocation failures combined with insufficient error checking
could result in the construction and execution of an argument sequence that
was not intended.

Fix that treating malloc(3) failures as fatal condition.

Submitted by:	brooks
Security:	FreeBSD-SA-16:36.telnetd
2016-12-06 18:50:22 +00:00
Dimitry Andric
866616de6e Fix warnings in telnet about invalid constant conversions, e.g.:
contrib/telnet/telnet/commands.c:2914:13: error: implicit conversion
from 'int' to 'char' changes value from 137 to -119
[-Werror,-Wconstant-conversion]
                *lsrp++ = IPOPT_SSRR;
                        ~ ^~~~~~~~~~
/usr/include/netinet/ip.h:152:21: note: expanded from macro 'IPOPT_SSRR'
#define IPOPT_SSRR              137             /* strict source route */
                                ^~~
contrib/telnet/telnet/commands.c:2916:13: error: implicit conversion
from 'int' to 'char' changes value from 131 to -125
[-Werror,-Wconstant-conversion]
                *lsrp++ = IPOPT_LSRR;
                        ~ ^~~~~~~~~~
/usr/include/netinet/ip.h:148:21: note: expanded from macro 'IPOPT_LSRR'
#define IPOPT_LSRR              131             /* loose source route */
                                ^~~

Use unsigned char buffers instead.

MFC after:	1 week
2016-08-30 20:27:22 +00:00
Dimitry Andric
c43262580d Squelch clang 3.9.0 warnings about BASE (which is 32768) being converted
to -32768 when it is used as an argument to mp_itom(), in both libtelnet
and newkey.  This code has been wrong since r26238 (!), so after almost
20 years it is rather useless to try to correct it.

MFC after:	1 week
2016-08-30 19:02:15 +00:00
Enji Cooper
ad11def521 Add baud rate support to telnet(1)
This implements part of RFC-2217

It's based off a patch originally written by Sujal Patel at Isilon, and
contributions from other Isilon employees.

PR: 173728
Phabric: D995
Reviewed by: markj, markm
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division
2014-11-11 04:06:05 +00:00
Marcel Moolenaar
6df39cc949 Improve upon previous commit:
1.  Check return of mmap(2) (*)
2.  Avoid FD leak when fstat fails.
3.  Fix style(9).

(*) Pointed out by jmg@
2014-03-02 03:34:06 +00:00
Marcel Moolenaar
8c82820bc3 Revive support for /etc/issue, lost due revision 81963.
Obtained from:	Juniper Networks, Inc.
2014-03-02 00:47:47 +00:00
Simon J. Gerraty
1a02b48ede Propagate ancient fix from Junos.
Use of -h is not supposed to depend on AUTHENTICATION being defined.

Reviewed by: markm
2013-11-07 00:36:39 +00:00
Marcel Moolenaar
f2e6a017d5 Fix "automatic" login, broken by revision 69825 (12 years, 5 months ago).
The "automatic" login feature is described as follows:
The USER environment variable holds the name of the person telnetting in.
This is the username of the person on the client machine. The traditional
behaviour is to execute login(1) with this username first, meaning that
login(1) will prompt for the password only. If login fails, login(1) will
retry, but now prompt for the username before prompting for the password.

This feature got broken by how the environment got scrubbed. Before the
change in r69825 we removed variables that we deemed dangerous. Starting
with r69825 we only keep those variable we know to be safe.

The USER environment variable fell through the cracks. It suddenly got
scrubbed (i.e. removed from the environment) while still being checked
for. It also got explicitly removed from the environment to handle the
failed login case.

The fix is to obtain the value of the USER environment variable before
we scrub the environment and used the "cached" in subsequent checks.
This guarantees that the environment does not contain the USER variable
in the end, while still being able to implement "automatic" login.

Obtained from:	Juniper Networks, Inc.
2013-05-31 17:30:12 +00:00
Kevin Lo
ba670ce023 Make sure that each va_start has one and only one matching va_end,
especially in error cases.
2012-09-28 07:51:30 +00:00
Joel Dahl
5febe54f25 Remove superfluous paragraph macro. 2012-06-17 11:04:38 +00:00
Stanislav Sedov
3ef51c5fb9 - Do not use deprecated krb5 error message reporting functions in libtelnet. 2012-04-06 00:03:45 +00:00
Colin Percival
3e65b9c6e6 Fix a problem whereby a corrupt DNS record can cause named to crash. [11:06]
Add an API for alerting internal libc routines to the presence of
"unsafe" paths post-chroot, and use it in ftpd. [11:07]

Fix a buffer overflow in telnetd. [11:08]

Make pam_ssh ignore unpassphrased keys unless the "nullok" option is
specified. [11:09]

Add sanity checking of service names in pam_start. [11:10]

Approved by:    so (cperciva)
Approved by:    re (bz)
Security:       FreeBSD-SA-11:06.bind
Security:       FreeBSD-SA-11:07.chroot
Security:       FreeBSD-SA-11:08.telnetd
Security:       FreeBSD-SA-11:09.pam_ssh
Security:       FreeBSD-SA-11:10.pam
2011-12-23 15:00:37 +00:00
Dimitry Andric
e9db6b2474 In contrib/telnet/telnet/utilities.c, fix a few warnings about format
strings not being literals.

MFC after:	1 week
2011-12-17 18:18:36 +00:00
Dimitry Andric
1f8811efbc In contrib/telnet/telnetd/utility.c, fix a few warnings about format
strings not being literals.

MFC after:	1 week
2011-12-16 16:53:54 +00:00
Dimitry Andric
675be9115a In contrib/telnet/libtelnet/sra.c, use the correct number of bytes to
zero the password buffer.

MFC after:	1 week
2011-12-16 00:48:53 +00:00
Jilles Tjoelker
524461f158 telnet: Fix infinite loop if local output generates SIGPIPE.
Instead of catching SIGPIPE and jumping out of the signal handler with
longjmp, ignore it and handle write errors to the local output by exiting
from there. I have changed the error message to mention the local output
instead of NetBSD's wrong "Connection closed by foreign host". Write errors
to the network were already handled by exiting immediately and this now
applies to EPIPE too.

The code assumed that SIGPIPE could only be generated by the network
connection; if it was generated by the local output, it would longjmp out of
the signal handler and write an error message which caused another SIGPIPE.

PR:		19773
Obtained from:	NetBSD
MFC after:	1 week
2010-04-30 19:52:35 +00:00
Ed Schouten
c36be85f01 Forgot a part that was missing in the previous commit.
There is no need to call trimdomain() anymore now that ut_host is big
enough to fit decent hostnames.
2010-01-13 18:46:50 +00:00
Ed Schouten
c2fd39cb4d Let telnetd build without utmp and logwtmp(3).
Just like rlogind, there is no need to change the ownership of the
terminal during shutdown anymore. Also don't call logwtmp, because the
login(1)/PAM is responsible for doing this. Also use SHUT_RDWR instead
of 2.
2010-01-13 18:37:42 +00:00
Ed Schouten
cea2194d9c Remove unneeded inclusion of <utmp.h> and dead variables. 2009-12-27 11:56:32 +00:00
Ed Schouten
ea74c11fae Use <termios.h> instead of <sys/termios.h>.
<sys/termios.h> only works on FreeBSD by accident.
2009-11-28 11:57:25 +00:00
Ed Schouten
b3aaa0cc21 Rename all symbols in libmp(3) to mp_*, just like Solaris.
The function pow() in libmp(3) clashes with pow(3) in libm. We could
rename this single function, but we can just take the same approach as
the Solaris folks did, which is to prefix all function names with mp_.

libmp(3) isn't really popular nowadays. I suspect not a single
application in ports depends on it. There's still a chance, so I've
increased the SHLIB_MAJOR and __FreeBSD_version.

Reviewed by:	deischen, rdivacky
2009-02-26 21:43:15 +00:00
Colin Percival
3a5733c67b Correctly scrub telnetd's environment.
Approved by:	so (cperciva)
Security:	FreeBSD-SA-09:05.telnetd
2009-02-16 21:56:17 +00:00