From 216e4ab74df61f1c15c0ec1394e8aba3d4d2de0f Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 26 Apr 2026 10:36:39 -0300 Subject: Reject overlong input with ERR_INPUTTOOLONG process-message! now rejects lines whose payload exceeds 510 bytes or whose tags exceed 4094 bytes with 417 ERR_INPUTTOOLONG instead of silently truncating, matching IRCv3 message-tags expectations. --- src/papod.clj | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/papod.clj b/src/papod.clj index 4055e8a..8b7d4d5 100644 --- a/src/papod.clj +++ b/src/papod.clj @@ -3862,11 +3862,38 @@ [(str "BATCH -" batch-id)])) w))))) +(defn- byte-length + [^String s] + (alength (.getBytes s "UTF-8"))) + +(defn- input-too-long? + [^String raw] + (let [tagged? (.startsWith raw "@") + sp (when tagged? (.indexOf raw " ")) + tags (when (and tagged? (pos? sp)) + (subs raw 1 sp)) + body (cond + (not tagged?) raw + (pos? sp) (subs raw (inc sp)) + :else "") + tag-len (if tags (byte-length tags) 0) + body-len (byte-length body)] + (or (and tagged? (> tag-len 4094)) + (> body-len 510)))) + (defn- process-message! [raw-message w client components] - (let [[message err] (parse-message raw-message)] - (when-not err - (handle-message! message w client components)))) + (cond + (input-too-long? raw-message) + (let [nick (or (:nick @client) "*") + line (str ":" +server-name+ " 417 " nick + " :Input line was too long")] + (deliver-to-client! w line)) + + :else + (let [[message err] (parse-message raw-message)] + (when-not err + (handle-message! message w client components))))) (defn- process-input! [input w client components] -- cgit v1.3