diff options
| author | EuAndreh <eu@euandre.org> | 2026-04-26 10:36:39 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-04-26 10:36:39 -0300 |
| commit | 216e4ab74df61f1c15c0ec1394e8aba3d4d2de0f (patch) | |
| tree | 069452c0c8f1d0f4666334e69f68d615a9c4660d /src | |
| parent | Improve labeled-response, TAGMSG, and parser robustness (diff) | |
| download | papod-216e4ab74df61f1c15c0ec1394e8aba3d4d2de0f.tar.gz papod-216e4ab74df61f1c15c0ec1394e8aba3d4d2de0f.tar.xz | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/papod.clj | 33 |
1 files changed, 30 insertions, 3 deletions
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] |
