Skip to content

Improve cleaning of messages - #2217

Merged
jubalh merged 5 commits into
masterfrom
fix/2210-clean-msgs
Oct 14, 2026
Merged

jubalh merged 5 commits into
masterfrom
fix/2210-clean-msgs

Conversation

@jubalh

@jubalh jubalh commented Oct 10, 2026

Copy link
Copy Markdown
Member

No description provided.

When a MUC or private message contained \u200E (LRM) or \u200F (RLM),
_cut() freed message->plain and allocated a new string.

Callers saved old_plain and restored it after running plugin hooks.
This left message->plain pointing to already freed memory, which caused
a crash with double free when message_free() was called.

Now we clean the directional characters in-place without reallocating
or freeing the string.

Fixes: #2210
Signed-off-by: Michael Vetter <jubalh@iodoru.org>
Now we also filter:
* Arabic Letter Mark (U+061C)
* Embeddings and overrides (U+202A to U+202E)
* Isolates (U+2066 to U+2069)

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
In plain XMPP and OMEMO, XML 1.0 already rejects most C0 control
characters. However, terminal escape sequences can still reach the
message buffer in several situations:
* OTR and legacy PGP decrypt raw bytes directly into the
message buffer without passing through an XML parser.
* XML 1.0 allows entity-encoded carriage return (&#xD; / \r), which in a
terminal can overwrite preceding text on the current line.
* XML 1.0 allows DEL (0x7F) and C1 controls (U+0080 to U+009F), where
U+009B acts as an 8-bit escape introducer (CSI) in many terminals.

Preserve legitimate \t and \n whitespace characters.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
Extract the common string traversal and in-place compacting logic
from str_clean_directional_chars() and str_clean_terminal_control_chars()
into a shared static helper _str_clean_chars().

Each cleaner now defines a small filter function and passes it to the
shared helper.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
@jubalh

jubalh commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

Reviewers welcome

Replace the \u0080, \u009B, and \u009F UCNs with their corresponding
UTF-8 hex byte sequences (\xc2\x80, \xc2\x9b, \xc2\x9f) to make clang
happy.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
@jubalh
jubalh force-pushed the fix/2210-clean-msgs branch from 6af9c9c to 05272f4 Compare October 11, 2026 07:36
@jubalh
jubalh merged commit 6f2a5c1 into master Oct 14, 2026
12 checks passed
@jubalh
jubalh deleted the fix/2210-clean-msgs branch October 14, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant