mirror of
https://gitee.com/openharmony/third_party_python
synced 2024-11-23 07:19:45 +00:00
!38 python-3.10漏洞升级 CVE-2021-3177
Merge pull request !38 from lsn1028/lsn_python_I65Q7F
This commit is contained in:
commit
6970e49eac
@ -244,6 +244,92 @@ class SimpleTypesTestCase(unittest.TestCase):
|
||||
self.assertRegex(repr(c_wchar_p.from_param('hihi')), r"^<cparam 'Z' \(0x[A-Fa-f0-9]+\)>$")
|
||||
self.assertRegex(repr(c_void_p.from_param(0x12)), r"^<cparam 'P' \(0x0*12\)>$")
|
||||
|
||||
def test_parameter_repr(self):
|
||||
from ctypes import (
|
||||
c_bool,
|
||||
c_char,
|
||||
c_wchar,
|
||||
c_byte,
|
||||
c_ubyte,
|
||||
c_short,
|
||||
c_ushort,
|
||||
c_int,
|
||||
c_uint,
|
||||
c_long,
|
||||
c_ulong,
|
||||
c_longlong,
|
||||
c_ulonglong,
|
||||
c_float,
|
||||
c_double,
|
||||
c_longdouble,
|
||||
c_char_p,
|
||||
c_wchar_p,
|
||||
c_void_p,
|
||||
)
|
||||
self.assertRegex(repr(c_bool.from_param(True)), r"^<cparam '\?' at 0x[A-Fa-f0-9]+>$")
|
||||
self.assertEqual(repr(c_char.from_param(97)), "<cparam 'c' ('a')>")
|
||||
self.assertRegex(repr(c_wchar.from_param('a')), r"^<cparam 'u' at 0x[A-Fa-f0-9]+>$")
|
||||
self.assertEqual(repr(c_byte.from_param(98)), "<cparam 'b' (98)>")
|
||||
self.assertEqual(repr(c_ubyte.from_param(98)), "<cparam 'B' (98)>")
|
||||
self.assertEqual(repr(c_short.from_param(511)), "<cparam 'h' (511)>")
|
||||
self.assertEqual(repr(c_ushort.from_param(511)), "<cparam 'H' (511)>")
|
||||
self.assertRegex(repr(c_int.from_param(20000)), r"^<cparam '[li]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_uint.from_param(20000)), r"^<cparam '[LI]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_long.from_param(20000)), r"^<cparam '[li]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_ulong.from_param(20000)), r"^<cparam '[LI]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_longlong.from_param(20000)), r"^<cparam '[liq]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_ulonglong.from_param(20000)), r"^<cparam '[LIQ]' \(20000\)>$")
|
||||
self.assertEqual(repr(c_float.from_param(1.5)), "<cparam 'f' (1.5)>")
|
||||
self.assertEqual(repr(c_double.from_param(1.5)), "<cparam 'd' (1.5)>")
|
||||
self.assertEqual(repr(c_double.from_param(1e300)), "<cparam 'd' (1e+300)>")
|
||||
self.assertRegex(repr(c_longdouble.from_param(1.5)), r"^<cparam ('d' \(1.5\)|'g' at 0x[A-Fa-f0-9]+)>$")
|
||||
self.assertRegex(repr(c_char_p.from_param(b'hihi')), "^<cparam 'z' \(0x[A-Fa-f0-9]+\)>$")
|
||||
self.assertRegex(repr(c_wchar_p.from_param('hihi')), "^<cparam 'Z' \(0x[A-Fa-f0-9]+\)>$")
|
||||
self.assertRegex(repr(c_void_p.from_param(0x12)), r"^<cparam 'P' \(0x0*12\)>$")
|
||||
|
||||
def test_parameter_repr(self):
|
||||
from ctypes import (
|
||||
c_bool,
|
||||
c_char,
|
||||
c_wchar,
|
||||
c_byte,
|
||||
c_ubyte,
|
||||
c_short,
|
||||
c_ushort,
|
||||
c_int,
|
||||
c_uint,
|
||||
c_long,
|
||||
c_ulong,
|
||||
c_longlong,
|
||||
c_ulonglong,
|
||||
c_float,
|
||||
c_double,
|
||||
c_longdouble,
|
||||
c_char_p,
|
||||
c_wchar_p,
|
||||
c_void_p,
|
||||
)
|
||||
self.assertRegex(repr(c_bool.from_param(True)), r"^<cparam '\?' at 0x[A-Fa-f0-9]+>$")
|
||||
self.assertEqual(repr(c_char.from_param(97)), "<cparam 'c' ('a')>")
|
||||
self.assertRegex(repr(c_wchar.from_param('a')), r"^<cparam 'u' at 0x[A-Fa-f0-9]+>$")
|
||||
self.assertEqual(repr(c_byte.from_param(98)), "<cparam 'b' (98)>")
|
||||
self.assertEqual(repr(c_ubyte.from_param(98)), "<cparam 'B' (98)>")
|
||||
self.assertEqual(repr(c_short.from_param(511)), "<cparam 'h' (511)>")
|
||||
self.assertEqual(repr(c_ushort.from_param(511)), "<cparam 'H' (511)>")
|
||||
self.assertRegex(repr(c_int.from_param(20000)), r"^<cparam '[li]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_uint.from_param(20000)), r"^<cparam '[LI]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_long.from_param(20000)), r"^<cparam '[li]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_ulong.from_param(20000)), r"^<cparam '[LI]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_longlong.from_param(20000)), r"^<cparam '[liq]' \(20000\)>$")
|
||||
self.assertRegex(repr(c_ulonglong.from_param(20000)), r"^<cparam '[LIQ]' \(20000\)>$")
|
||||
self.assertEqual(repr(c_float.from_param(1.5)), "<cparam 'f' (1.5)>")
|
||||
self.assertEqual(repr(c_double.from_param(1.5)), "<cparam 'd' (1.5)>")
|
||||
self.assertEqual(repr(c_double.from_param(1e300)), "<cparam 'd' (1e+300)>")
|
||||
self.assertRegex(repr(c_longdouble.from_param(1.5)), r"^<cparam ('d' \(1.5\)|'g' at 0x[A-Fa-f0-9]+)>$")
|
||||
self.assertRegex(repr(c_char_p.from_param(b'hihi')), "^<cparam 'z' \(0x[A-Fa-f0-9]+\)>$")
|
||||
self.assertRegex(repr(c_wchar_p.from_param('hihi')), "^<cparam 'Z' \(0x[A-Fa-f0-9]+\)>$")
|
||||
self.assertRegex(repr(c_void_p.from_param(0x12)), r"^<cparam 'P' \(0x0*12\)>$")
|
||||
|
||||
################################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -0,0 +1,2 @@
|
||||
Avoid static buffers when computing the repr of :class:`ctypes.c_double` and
|
||||
:class:`ctypes.c_longdouble` values.
|
Loading…
Reference in New Issue
Block a user