From cff26a97afb3e47b5ec842f5307c2ea128b8ebc9 Mon Sep 17 00:00:00 2001 From: aryansri05 Date: Sun, 19 Oct 2025 00:11:36 +0530 Subject: [PATCH] Fix OTR whitespace tag detection to prevent false positives The previous implementation used strstr() which would match OTR tag patterns anywhere in the message. This caused normal messages containing these patterns to incorrectly trigger OTR session initialization. Changed to use strncmp() to verify that V1/V2 tags immediately follow the base tag, ensuring only legitimate OTR whitespace tags trigger session establishment. Fixes #1957 --- src/otr/otr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index 0a67bb03..383183fb 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -296,7 +296,8 @@ otr_on_message_recv(const char* const barejid, const char* const resource, const // check for OTR whitespace (opportunistic or always) if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) { if (whitespace_base) { - if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { + char* tag_position = whitespace_base + strlen(OTRL_MESSAGE_TAG_BASE); + if (strncmp(tag_position, OTRL_MESSAGE_TAG_V2, strlen(OTRL_MESSAGE_TAG_V2)) == 0 || strncmp(tag_position, OTRL_MESSAGE_TAG_V1, strlen(OTRL_MESSAGE_TAG_V1)) == 0) { // Remove whitespace pattern for proper display in UI // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8) int tag_length = 24;