HomeFreeBSD

telnet: Prevent buffer overflow in the user prompt for SRA

Description

telnet: Prevent buffer overflow in the user prompt for SRA

The Secure RPC authenticator for telnet prompts the local user for the
username to use for authentication. Previously it was using sprintf()
into a buffer of 256 bytes, but the username received over the wire
can be up to 255 bytes long which would overflow the prompt buffer.
Fix this in two ways: First, use snprintf() and check for overflow.
If the prompt buffer overflows, fail authentication without prompting
the user. Second, add 10 bytes to the buffer size to account for the
overhead of the prompt so that a maximally sized username fits.

While here, replace a bare 255 in the subsequent telnet_gets call with
an expression using sizeof() the relevant buffer.

PR: 270263
Reported by: Robert Morris <rtm@lcs.mit.edu>
Tested on: CHERI
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D49832

(cherry picked from commit 5737c2ae06e143e49496df2ab5a64f76d5456012)

Details

Provenance
jhbAuthored on Apr 16 2025, 1:41 PM
Reviewer
emaste
Differential Revision
D49832: telnet: Prevent buffer overflow in the user prompt for SRA
Parents
rG2ef9c17d68c4: release: Pass PKG_INSTALL_EPOCH (take 2)
Branches
Unknown
Tags
Unknown