File CVE-2025-15366-imap-ctrl-chars.patch of Package python.42782

From 7485ee5e2cf81d3e5ad0d9c3be73cecd2ab4eec7 Mon Sep 17 00:00:00 2001
From: Seth Michael Larson <seth@python.org>
Date: Fri, 16 Jan 2026 10:54:09 -0600
Subject: [PATCH 1/2] Add 'test.support' fixture for C0 control characters

---
 Lib/imaplib.py                                                           |    3 +++
 Lib/test/test_imaplib.py                                                 |    9 ++++++++-
 Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst |    1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

Index: Python-2.7.18/Lib/imaplib.py
===================================================================
--- Python-2.7.18.orig/Lib/imaplib.py	2020-04-19 23:13:39.000000000 +0200
+++ Python-2.7.18/Lib/imaplib.py	2026-02-13 22:03:45.901187184 +0100
@@ -104,6 +104,7 @@
 Response_code = re.compile(r'\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]')
 Untagged_response = re.compile(r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
 Untagged_status = re.compile(r'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?')
+_control_chars = re.compile(b'[\x00-\x1F\x7F]')
 
 
 
@@ -852,6 +853,8 @@
         data = '%s %s' % (tag, name)
         for arg in args:
             if arg is None: continue
+            if _control_chars.search(arg):
+                raise ValueError("Control characters not allowed in commands")
             data = '%s %s' % (data, self._checkquote(arg))
 
         literal = self.literal
Index: Python-2.7.18/Lib/test/test_imaplib.py
===================================================================
--- Python-2.7.18.orig/Lib/test/test_imaplib.py	2020-04-19 23:13:39.000000000 +0200
+++ Python-2.7.18/Lib/test/test_imaplib.py	2026-02-13 22:05:34.894106936 +0100
@@ -10,7 +10,8 @@
 import SocketServer
 import time
 
-from test_support import reap_threads, verbose, transient_internet
+from test_support import (reap_threads, verbose, transient_internet,
+                          control_characters_c0)
 import unittest
 
 try:
@@ -248,6 +249,12 @@
 
     support.run_unittest(*tests)
 
+    def test_control_characters(self):
+        client, _ = self._setup(SimpleIMAPHandler)
+        for c0 in control_characters_c0():
+            with self.assertRaises(ValueError):
+                client.login('user{}'.format(c0), 'pass')
+
 
 if __name__ == "__main__":
     test_main()
Index: Python-2.7.18/Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ Python-2.7.18/Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst	2026-02-13 22:01:28.389020838 +0100
@@ -0,0 +1 @@
+Reject control characters in IMAP commands.
openSUSE Build Service is sponsored by