File CVE-2025-61912-escape-nuls-correctly-escape-dn-chars.patch of Package python-ldap.41137

From 6ea80326a34ee6093219628d7690bced50c49a3f Mon Sep 17 00:00:00 2001
From: Simon Pichugin <simon.pichugin@gmail.com>
Date: Fri, 10 Oct 2025 10:46:45 -0700
Subject: [PATCH] Merge commit from fork

Update tests to expect \00 and verify RFC-compliant escaping
---
 Lib/ldap/dn.py     | 3 ++-
 Tests/t_ldap_dn.py | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

Index: python-ldap-3.1.0/Lib/ldap/dn.py
===================================================================
--- python-ldap-3.1.0.orig/Lib/ldap/dn.py
+++ python-ldap-3.1.0/Lib/ldap/dn.py
@@ -28,7 +28,8 @@ def escape_dn_chars(s):
     s = s.replace('>' ,'\\>')
     s = s.replace(';' ,'\\;')
     s = s.replace('=' ,'\\=')
-    s = s.replace('\000' ,'\\\000')
+    # RFC 4514 requires NULL (U+0000) to be escaped as hex pair "\00"
+    s = s.replace('\x00' ,'\\00')
     if s[0]=='#' or s[0]==' ':
       s = ''.join(('\\',s))
     if s[-1]==' ':
Index: python-ldap-3.1.0/Tests/t_ldap_dn.py
===================================================================
--- python-ldap-3.1.0.orig/Tests/t_ldap_dn.py
+++ python-ldap-3.1.0/Tests/t_ldap_dn.py
@@ -50,6 +50,7 @@ class TestDN(unittest.TestCase):
         self.assertEqual(ldap.dn.escape_dn_chars('#foobar'), '\\#foobar')
         self.assertEqual(ldap.dn.escape_dn_chars('foo bar'), 'foo bar')
         self.assertEqual(ldap.dn.escape_dn_chars(' foobar'), '\\ foobar')
+        self.assertEqual(ldap.dn.escape_dn_chars('f+o>o,b<a;r="\00"'), r'f\+o\>o\,b\<a\;r\=\"\00\"')
 
     def test_str2dn(self):
         """
openSUSE Build Service is sponsored by