Skip to content

Commit

Permalink
Return ERR_INPUTTOOLONG instead of closing connection on messages lon…
Browse files Browse the repository at this point in the history
…ger than ~1020 bytes

As recommended by https://ircv3.net/specs/extensions/message-tags#size-limit
  • Loading branch information
progval authored and spb committed Aug 11, 2024
1 parent 16cd4a1 commit 7db845c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
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

0 comments on commit 7db845c

Please sign in to comment.