[3.6] bpo-13617: Reject embedded null characters in wchar* strings. (GH-2302) (#2462)

Based on patch by Victor Stinner.

Add private C API function _PyUnicode_AsUnicode() which is similar to
PyUnicode_AsUnicode(), but checks for null characters..
(cherry picked from commit f7eae0adfc)
This commit is contained in:
Serhiy Storchaka 2017-06-28 09:27:35 +03:00 committed by GitHub
parent 413c0a92bc
commit 0834905d9b
22 changed files with 115 additions and 24 deletions

View file

@ -81,7 +81,7 @@ class TestCurses(unittest.TestCase):
win2 = curses.newwin(15,15, 5,5)
for meth in [stdscr.addch, stdscr.addstr]:
for args in [('a'), ('a', curses.A_BOLD),
for args in [('a',), ('a', curses.A_BOLD),
(4,4, 'a'), (5,5, 'a', curses.A_BOLD)]:
with self.subTest(meth=meth.__qualname__, args=args):
meth(*args)
@ -194,6 +194,15 @@ class TestCurses(unittest.TestCase):
self.assertRaises(ValueError, stdscr.instr, -2)
self.assertRaises(ValueError, stdscr.instr, 2, 3, -2)
def test_embedded_null_chars(self):
# reject embedded null bytes and characters
stdscr = self.stdscr
for arg in ['a', b'a']:
with self.subTest(arg=arg):
self.assertRaises(ValueError, stdscr.addstr, 'a\0')
self.assertRaises(ValueError, stdscr.addnstr, 'a\0', 1)
self.assertRaises(ValueError, stdscr.insstr, 'a\0')
self.assertRaises(ValueError, stdscr.insnstr, 'a\0', 1)
def test_module_funcs(self):
"Test module-level functions"