Skip to content

Comments

Fix telnet_send_command_with_output returning the input#904

Open
untitaker wants to merge 1 commit intomainfrom
telnet-refactor
Open

Fix telnet_send_command_with_output returning the input#904
untitaker wants to merge 1 commit intomainfrom
telnet-refactor

Conversation

@untitaker
Copy link
Collaborator

@untitaker untitaker commented Feb 19, 2026

telnet_send_command_with_output returns output with the original command
contained. This leads to higher-level bugs. Fix #894

Also, change telnet_send_command_with_output to not return any "exit
code" related output. This is now only part of telnet_send_command,
which means this output does not leak into users of the DeviceConnection
trait (Which uses telnet_send_command_with_output)

telnet_send_command is not a great API because users expect the
exit code 0 string to be part of output, but it's too widely used to
change it now.

telnet_send_command_with_output returns output with the original command
contained. This leads to higher-level bugs. Fix #894

Also, change telnet_send_command_with_output to not return any "exit
code" related output. This is now only part of telnet_send_command,
which means this output does not leak into users of the DeviceConnection
trait.
@untitaker untitaker marked this pull request as ready for review February 19, 2026 19:40
Copy link
Collaborator

@wgreenberg wgreenberg left a comment

Choose a reason for hiding this comment

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

haven't tested this yet, but i like the approach. just a few comments/questions

command: &str,
wait_for_prompt: bool,
) -> Result<String> {
debug_assert!(!command.contains('\n'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not assert!? afaik debug_assert should only be used when performance is an issue

let response = String::from_utf8_lossy(&read_buf);
if response.contains("command done, exit code ") {
break;
if byte == b'\n' {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm not sure this will actually come up, but i think a consequence of doing byte-by-byte equality is if the output contains non-ASCII UTF-8 data, we may get a false positive on the newline check

//
// 'TELNET' is quoted so that when the command gets echoed back, it does not match against
// RAYHUNTER_TELNET_COMMAND_DONE search string.
writer.write_all(format!("echo RAYHUNTER_'TELNET'_COMMAND_START; {command}; echo RAYHUNTER_'TELNET'_COMMAND_DONE\r\n").as_bytes()).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a clever hack!

let start = start + "RAYHUNTER_TELNET_COMMAND_START".len();
string[start..end].trim_start_matches(['\r', '\n'])
}
_ => &string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

am i wrong in thinking we want to error out in this case?

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.

TP Link M7350 Installation not working

2 participants