summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-11-29 15:45:21 (GMT)
committerGitHub <noreply@github.com>2024-11-29 15:45:21 (GMT)
commitc4a359dc426bcb1a5f16ef25b0e3110bb463bdad (patch)
treed0c2f1aad4a09f098836189885f4f3ba43bec39d /Python
parent6a0663404b6c76a6d137776b1912f58ad44e8c86 (diff)
downloadcpython-c4a359dc426bcb1a5f16ef25b0e3110bb463bdad.zip
cpython-c4a359dc426bcb1a5f16ef25b0e3110bb463bdad.tar.gz
cpython-c4a359dc426bcb1a5f16ef25b0e3110bb463bdad.tar.bz2
[3.13] gh-127208: Reject null character in _imp.create_dynamic() (GH-127400) (#127418)
gh-127208: Reject null character in _imp.create_dynamic() (GH-127400) _imp.create_dynamic() now rejects embedded null characters in the path and in the module name. (cherry picked from commit b14fdadc6c620875a20b7ccc3c9b069e85d8557a) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/import.c b/Python/import.c
index 0f08e6d..ea5a3e4 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1155,12 +1155,14 @@ del_extensions_cache_value(struct extensions_cache_value *value)
static void *
hashtable_key_from_2_strings(PyObject *str1, PyObject *str2, const char sep)
{
- Py_ssize_t str1_len, str2_len;
- const char *str1_data = PyUnicode_AsUTF8AndSize(str1, &str1_len);
- const char *str2_data = PyUnicode_AsUTF8AndSize(str2, &str2_len);
+ const char *str1_data = _PyUnicode_AsUTF8NoNUL(str1);
+ const char *str2_data = _PyUnicode_AsUTF8NoNUL(str2);
if (str1_data == NULL || str2_data == NULL) {
return NULL;
}
+ Py_ssize_t str1_len = strlen(str1_data);
+ Py_ssize_t str2_len = strlen(str2_data);
+
/* Make sure sep and the NULL byte won't cause an overflow. */
assert(SIZE_MAX - str1_len - str2_len > 2);
size_t size = str1_len + 1 + str2_len + 1;