Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ERR_INPUTTOOLONG instead of closing connection on messages longer than ~1020 bytes #135

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client_listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"
[dependencies]
sable_macros = { path = "../sable_macros" }
sable_ipc = { path = "../sable_ipc" }
bincode = "1.3"
tracing = "0.1"
thiserror = "1"
serde = { version = "1", features = [ "derive" ] }
Expand Down
2 changes: 2 additions & 0 deletions client_listener/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum ConnectionError {
InternalError,
#[error("Send queue full")]
SendQueueFull,
#[error("Input line was too long")]
InputLineTooLong,
}

/// An error that might occur when configuring a listener.
Expand Down
6 changes: 5 additions & 1 deletion client_listener/src/internal/connection_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ where
message = lines.next_line() => match message {
Ok(None) => { break; },
Ok(Some(m)) => {
if self.event_channel.send(InternalConnectionEventType::Event(InternalConnectionEvent::Message(self.id, m))).await.is_err() {
if m.as_bytes().len() as u64 > crate::MAX_MSG_SIZE {
if self.event_channel.send(InternalConnectionEventType::Event(InternalConnectionEvent::ConnectionError(self.id, ConnectionError::InputLineTooLong))).await.is_err() {
tracing::error!("Error notifying socket error on connection {:?}", self.id);
}
} else if self.event_channel.send(InternalConnectionEventType::Event(InternalConnectionEvent::Message(self.id, m))).await.is_err() {
tracing::error!("Error notifying socket message on connection {:?}", self.id);
}
}
Expand Down
1 change: 1 addition & 0 deletions sable_ircd/src/messages/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ define_messages! {
406(WasNoSuchNick) => { (nick: &Nickname) => "{nick} :There was no such nickname" },
410(InvalidCapCmd) => { (subcommand: &str) => "{subcommand} :Invalid CAP command" },
412(NoTextToSend) => { () => ":No text to send" },
417(InputTooLong) => { () => ":Input line was too long" },
421(UnknownCommand) => { (command: &str) => "{command} :Unknown command" },
432(ErroneousNickname) => { (nick: &str) => "{nick} :Erroneous nickname" },
433(NicknameInUse) => { (nick: &Nickname) => "{nick} :Nickname is already in use." },
Expand Down
10 changes: 9 additions & 1 deletion sable_ircd/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@ impl ClientServer {
.await;
}
}
conn.send(message::Error::new(&e.to_string()));
match e {
ConnectionError::InputLineTooLong => {
conn.send(numeric::InputTooLong::new_for(
&self.node.name().to_string(),
&"*".to_string(),
))
}
_ => conn.send(message::Error::new(&e.to_string())),
}
}
self.connections.write().remove(msg.source);
}
Expand Down
Loading