Skip to content

telnet: make it work through proxy tunnels - #22941

Closed
icing wants to merge 1 commit into
curl:masterfrom
icing:telnet-tunnel-proxy
Closed

icing wants to merge 1 commit into
curl:masterfrom
icing:telnet-tunnel-proxy

Conversation

@icing

@icing icing commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Change telnet's antiquated corner places where it still used the connection socket directly. Use the transfer send call instead which goes the proper way thought the connection filters.

Change telnet's antiquated corner places where it still used
the connection socket directly. Use the transfer send call
instead which goes the proper way thought the connection filters.
@icing
icing requested a review from bagder September 14, 2026 08:26
@bagder
bagder requested a balanced review from Copilot September 14, 2026 08:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new sends ignore partial and zero-byte writes, which can truncate Telnet negotiation messages.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Routes Telnet control messages through connection filters to support proxy tunnels.

Changes:

  • Replaces direct socket writes with Curl_xfer_send().
  • Reports filter-aware send errors.
File summaries
File Description
lib/telnet.c Routes Telnet negotiation and suboption writes through transfer filters.
Review details

Suppressed comments (4)

lib/telnet.c:706

  • This send may consume fewer than 3 bytes, including zero bytes when the filter is blocked, while returning CURLE_OK. The code then sends the window-size body, producing a malformed subnegotiation stream. Retry the unsent header before proceeding to the body.
    result = Curl_xfer_send(data, tn->subbuffer, 3, FALSE, &nwritten);

lib/telnet.c:713

  • The footer is discarded if Curl_xfer_send() reports a successful short or zero-byte write. This leaves the NAWS subnegotiation unterminated; retry until both footer bytes have been consumed and return any send failure to the transfer.
    result = Curl_xfer_send(data, tn->subbuffer + 7, 2, FALSE, &nwritten);

lib/telnet.c:1014

  • This XDISPLOC response is silently truncated whenever the connection filter consumes fewer than len bytes, because nwritten is never checked. Loop or buffer the unconsumed suffix before treating the suboption as sent.
    result = Curl_xfer_send(data, temp, len, FALSE, &nwritten);

lib/telnet.c:1046

  • This environment response can be much larger than one filter write, but the code ignores nwritten and returns success after a partial or zero-byte write. Preserve and retry the remainder so the Telnet subnegotiation is not truncated.
    result = Curl_xfer_send(data, temp, len, FALSE, &nwritten);
  • Files reviewed: 1/1 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/telnet.c
bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0)
failf(data, "Sending data failed (%d)", SOCKERRNO);
result = Curl_xfer_send(data, buf, 3, FALSE, &nwritten);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What even is this?

Comment thread lib/telnet.c
if(bytes_written < 0) {
failf(data, "Sending data failed (%d)", SOCKERRNO);
return CURLE_SEND_ERROR;
result = Curl_xfer_send(data, temp, len, FALSE, &nwritten);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What am I doing here?

Comment thread lib/telnet.c
bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0)
failf(data, "Sending data failed (%d)", SOCKERRNO);
result = Curl_xfer_send(data, buf, 3, FALSE, &nwritten);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this were a human, violence would creep into my mind.

@bagder

bagder commented Sep 14, 2026

Copy link
Copy Markdown
Member

In the mean time, I made this: #22943

@icing

icing commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

This protocol handler, like all the pingpoing ones, is from another age and time. When Elves still wandered the earth and unicorns were roaming the forests...

@bagder

bagder commented Sep 14, 2026

Copy link
Copy Markdown
Member

the good old days! 🦄

@bagder bagder closed this in 3f79dc3 Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants