File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -1133,6 +1133,19 @@ def test_script_shadowing_stdlib_sys_path_modification(self):
11331133 stdout , stderr = popen .communicate ()
11341134 self .assertRegex (stdout , expected_error )
11351135
1136+ def test_create_dynamic_null (self ):
1137+ with self .assertRaisesRegex (ValueError , 'embedded null character' ):
1138+ class Spec :
1139+ name = "a\x00 b"
1140+ origin = "abc"
1141+ _imp .create_dynamic (Spec ())
1142+
1143+ with self .assertRaisesRegex (ValueError , 'embedded null character' ):
1144+ class Spec2 :
1145+ name = "abc"
1146+ origin = "a\x00 b"
1147+ _imp .create_dynamic (Spec2 ())
1148+
11361149
11371150@skip_if_dont_write_bytecode
11381151class FilePermissionTests (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -1157,12 +1157,14 @@ del_extensions_cache_value(struct extensions_cache_value *value)
11571157static void *
11581158hashtable_key_from_2_strings (PyObject * str1 , PyObject * str2 , const char sep )
11591159{
1160- Py_ssize_t str1_len , str2_len ;
1161- const char * str1_data = PyUnicode_AsUTF8AndSize (str1 , & str1_len );
1162- const char * str2_data = PyUnicode_AsUTF8AndSize (str2 , & str2_len );
1160+ const char * str1_data = _PyUnicode_AsUTF8NoNUL (str1 );
1161+ const char * str2_data = _PyUnicode_AsUTF8NoNUL (str2 );
11631162 if (str1_data == NULL || str2_data == NULL ) {
11641163 return NULL ;
11651164 }
1165+ Py_ssize_t str1_len = strlen (str1_data );
1166+ Py_ssize_t str2_len = strlen (str2_data );
1167+
11661168 /* Make sure sep and the NULL byte won't cause an overflow. */
11671169 assert (SIZE_MAX - str1_len - str2_len > 2 );
11681170 size_t size = str1_len + 1 + str2_len + 1 ;
You can’t perform that action at this time.
0 commit comments