From 6410cefc97f2057e519fbbb857ff73220b2d2b2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@cepl.eu>
Date: Sun, 20 Sep 2026 23:19:02 +0200
Subject: [PATCH] [CVE-2026-3479] Fix pkgutil.get_data() documentation

The documentation still claimed that get_data() can follow parent
directories and absolute paths, which contradicts the validation added
for CVE-2026-3479.  Also register the `cve` Sphinx role used by the
NEWS entry for this CVE.

Fixes: bsc#1259989 (CVE-2026-3479)
Patch: CVE-2026-3479-pkgutil_get_data-docs.patch
---
 Doc/library/pkgutil.rst            |    7 ++++---
 Doc/tools/extensions/pyspecific.py |   11 +++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

Index: Python-3.6.15/Doc/library/pkgutil.rst
===================================================================
--- Python-3.6.15.orig/Doc/library/pkgutil.rst	2026-09-21 01:53:36.038409770 +0200
+++ Python-3.6.15/Doc/library/pkgutil.rst	2026-09-21 01:53:40.295547406 +0200
@@ -226,9 +226,10 @@
       d = os.path.dirname(sys.modules[package].__file__)
       data = open(os.path.join(d, resource), 'rb').read()
 
-   Like the :func:`open` function, :func:`!get_data` can follow parent
-   directories (``../``) and absolute paths (starting with ``/`` or ``C:/``,
-   for example).
+   The *resource* argument must be a relative path that stays within the
+   package directory.  Absolute paths (starting with ``/`` or ``C:/``,
+   for example) and paths containing a parent directory component
+   (``..``) raise :exc:`ValueError`.
 
    .. warning::
 
Index: Python-3.6.15/Doc/tools/extensions/pyspecific.py
===================================================================
--- Python-3.6.15.orig/Doc/tools/extensions/pyspecific.py	2026-09-21 01:53:35.216660042 +0200
+++ Python-3.6.15/Doc/tools/extensions/pyspecific.py	2026-09-21 01:53:40.295797657 +0200
@@ -41,6 +41,7 @@
 
 ISSUE_URI = 'https://bugs.python.org/issue%s'
 SOURCE_URI = 'https://github.com/python/cpython/tree/3.6/%s'
+CVE_URI = 'https://www.cve.org/CVERecord?id=CVE-%s'
 
 # monkey-patch reST parser to disable alphabetic and roman enumerated lists
 from docutils.parsers.rst.states import Body
@@ -90,6 +91,15 @@
     return [refnode], []
 
 
+# Support for linking to CVE records in backported NEWS entries.
+
+def cve_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
+    cve = utils.unescape(text)
+    text = 'CVE-' + cve
+    refnode = nodes.reference(text, text, refuri=CVE_URI % cve)
+    return [refnode], []
+
+
 # Support for linking to Python source files easily
 
 def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
@@ -400,6 +410,7 @@
 def setup(app):
     app.add_role('issue', issue_role)
     app.add_role('source', source_role)
+    app.add_role('cve', cve_role)
     app.add_directive('impl-detail', ImplementationDetail)
     app.add_directive('deprecated-removed', DeprecatedRemoved)
     app.add_builder(PydocTopicsBuilder)
