Skip to content

Fixes on the telnet rewrite - #71

Merged
jonrebm merged 7 commits into
mainfrom
telnet_seq
Oct 14, 2026
Merged

jonrebm merged 7 commits into
mainfrom
telnet_seq

Conversation

@jonrebm

@jonrebm jonrebm commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Since the telnet rewrite in 5cf691b, issues of escape sequences wrongfully printed to the console have been reported from users of the telnet backend. This is mainly addressed by telnet.c: fix handling of successive command sequences, this PR accompanies the fix with regression tests, improvements in test coverage overall, and a few other issues in telnet.c resolved as well.

@jonrebm
jonrebm force-pushed the telnet_seq branch 2 times, most recently from bc2475d to 0ede3e2 Compare October 12, 2026 15:09
@Bastian-Krause

Copy link
Copy Markdown
Member

Seems to fix rfc2218 connections where microcom exitted earlier with ������Got EOF from port. 👍

memchr() may be type-generic returning const if the supplied ptr
argument is const, resulting in a discarded-qualifiers warning.

Silence it by keeping the const qualifier.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Add some more test cases, most noticeably cover DO and WILL sequences.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
@jonrebm
jonrebm force-pushed the telnet_seq branch 2 times, most recently from 25c487d to 40579a6 Compare October 13, 2026 12:53
@jonrebm

jonrebm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Fixed three typos and added 40579a6

@jonrebm
jonrebm requested a review from saschahauer October 14, 2026 06:28
The telnet command handling was implemented to skip one character after
handling each command, which made handling IAC,IAC sequences in
handle_iac() much easier but fails to handle sequences in direct
succession.

Allow handling a new control sequence right after one ended. To still
allow handle_iac() to emit a literal IAC, introduce a new private bool
in telnet_ios that signals the caller to skip the second IAC byte.

Fixes: 5cf691b ("telnet.c: rewrite command handling")
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
handle_iac() consumes one byte too few at a subnegotiation, leaking the
0xf0 (Subneg End) into the output stream.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Returning 0 from telnet_read() when none of the bytes read produced any
output is interpreted as EOF.

Instead, handle this case as EAGAIN to avoid "Got EOF from port" from
mux_loop().

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
As the regression test shows, an SE occurring within a subneg any place
after an IAC would end the subneg, leading the regression to fail assert
b'before!after' == b'beforeafter'.

Conform to rfc854 by staying in the subneg until encountering IAC
immediately followed by SE.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>

@saschahauer saschahauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@jonrebm
jonrebm merged commit d28ae21 into main Oct 14, 2026
3 checks passed
@jonrebm
jonrebm deleted the telnet_seq branch October 14, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants