Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8b129f

Browse files
committed
Closes #21151: Merge with 3.4
2 parents a6237d8 + ad4690f commit d8b129f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lib/test/test_winreg.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def test_setvalueex_value_range(self):
341341
def test_queryvalueex_return_value(self):
342342
# Test for Issue #16759, return unsigned int from QueryValueEx.
343343
# Reg2Py, which gets called by QueryValueEx, was returning a value
344-
# generated by PyLong_FromLong. The implmentation now uses
344+
# generated by PyLong_FromLong. The implementation now uses
345345
# PyLong_FromUnsignedLong to match DWORD's size.
346346
try:
347347
with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
@@ -354,6 +354,19 @@ def test_queryvalueex_return_value(self):
354354
finally:
355355
DeleteKey(HKEY_CURRENT_USER, test_key_name)
356356

357+
def test_setvalueex_crash_with_none_arg(self):
358+
# Test for Issue #21151, segfault when None is passed to SetValueEx
359+
try:
360+
with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
361+
self.assertNotEqual(ck.handle, 0)
362+
test_val = None
363+
SetValueEx(ck, "test_name", 0, REG_BINARY, test_val)
364+
ret_val, ret_type = QueryValueEx(ck, "test_name")
365+
self.assertEqual(ret_type, REG_BINARY)
366+
self.assertEqual(ret_val, test_val)
367+
finally:
368+
DeleteKey(HKEY_CURRENT_USER, test_key_name)
369+
357370

358371

359372
@unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Core and Builtins
103103
Library
104104
-------
105105

106+
- Issue #21151: Fixed a segfault in the winreg module when ``None`` is passed
107+
as a ``REG_BINARY`` value to SetValueEx. Patch by John Ehresman.
108+
106109
- Issue #21090: io.FileIO.readall() does not ignore I/O errors anymore. Before,
107110
it ignored I/O errors if at least the first C call read() succeed.
108111

PC/winreg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,10 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
871871
/* ALSO handle ALL unknown data types here. Even if we can't
872872
support it natively, we should handle the bits. */
873873
default:
874-
if (value == Py_None)
874+
if (value == Py_None) {
875875
*retDataSize = 0;
876+
*retDataBuf = NULL;
877+
}
876878
else {
877879
Py_buffer view;
878880

0 commit comments

Comments
 (0)