File tree 2 files changed +18
-3
lines changed
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):
1133
1133
stdout , stderr = popen .communicate ()
1134
1134
self .assertRegex (stdout , expected_error )
1135
1135
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
+
1136
1149
1137
1150
@skip_if_dont_write_bytecode
1138
1151
class 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)
1157
1157
static void *
1158
1158
hashtable_key_from_2_strings (PyObject * str1 , PyObject * str2 , const char sep )
1159
1159
{
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 );
1163
1162
if (str1_data == NULL || str2_data == NULL ) {
1164
1163
return NULL ;
1165
1164
}
1165
+ Py_ssize_t str1_len = strlen (str1_data );
1166
+ Py_ssize_t str2_len = strlen (str2_data );
1167
+
1166
1168
/* Make sure sep and the NULL byte won't cause an overflow. */
1167
1169
assert (SIZE_MAX - str1_len - str2_len > 2 );
1168
1170
size_t size = str1_len + 1 + str2_len + 1 ;
You can’t perform that action at this time.
0 commit comments