mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
Backport also the _PyUnicode_AsUTF8NoNUL() function.
(cherry picked from commit b14fdadc6c
)
This commit is contained in:
parent
fc0564b365
commit
e7ab97862d
4 changed files with 33 additions and 3 deletions
|
@ -917,12 +917,14 @@ extensions_lock_release(void)
|
|||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue