diff options
author | Victor Stinner <vstinner@python.org> | 2024-11-29 15:20:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-29 15:20:38 (GMT) |
commit | b14fdadc6c620875a20b7ccc3c9b069e85d8557a (patch) | |
tree | 3ca2a93a5789cf56286c6516691c39da3d786246 /Python | |
parent | 3afb639f39e89888194d8e74cc498c8da3a58d8e (diff) | |
download | cpython-b14fdadc6c620875a20b7ccc3c9b069e85d8557a.zip cpython-b14fdadc6c620875a20b7ccc3c9b069e85d8557a.tar.gz cpython-b14fdadc6c620875a20b7ccc3c9b069e85d8557a.tar.bz2 |
gh-127208: Reject null character in _imp.create_dynamic() (#127400)
_imp.create_dynamic() now rejects embedded null characters in the
path and in the module name.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/import.c b/Python/import.c index 09fe95f..b3c384c 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1157,12 +1157,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; |