[Python-checkins] cpython (merge 3.4 -> default): Closes #21151: Merge with 3.4

zach.ware python-checkins at python.org
Thu Jul 3 18:04:17 CEST 2014


http://hg.python.org/cpython/rev/21cfbcacf0d8
changeset:   91538:21cfbcacf0d8
parent:      91535:06bdd7e8fffd
parent:      91537:0c5a1835af91
user:        Zachary Ware <zachary.ware at gmail.com>
date:        Thu Jul 03 11:03:46 2014 -0500
summary:
  Closes #21151: Merge with 3.4

files:
  Lib/test/test_winreg.py |  15 ++++++++++++++-
  Misc/NEWS               |   3 +++
  PC/winreg.c             |   4 +++-
  3 files changed, 20 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -341,7 +341,7 @@
     def test_queryvalueex_return_value(self):
         # Test for Issue #16759, return unsigned int from QueryValueEx.
         # Reg2Py, which gets called by QueryValueEx, was returning a value
-        # generated by PyLong_FromLong. The implmentation now uses
+        # generated by PyLong_FromLong. The implementation now uses
         # PyLong_FromUnsignedLong to match DWORD's size.
         try:
             with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
@@ -354,6 +354,19 @@
         finally:
             DeleteKey(HKEY_CURRENT_USER, test_key_name)
 
+    def test_setvalueex_crash_with_none_arg(self):
+        # Test for Issue #21151, segfault when None is passed to SetValueEx
+        try:
+            with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
+                self.assertNotEqual(ck.handle, 0)
+                test_val = None
+                SetValueEx(ck, "test_name", 0, REG_BINARY, test_val)
+                ret_val, ret_type = QueryValueEx(ck, "test_name")
+                self.assertEqual(ret_type, REG_BINARY)
+                self.assertEqual(ret_val, test_val)
+        finally:
+            DeleteKey(HKEY_CURRENT_USER, test_key_name)
+
 
 
 @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,9 @@
 Library
 -------
 
+- Issue #21151: Fixed a segfault in the winreg module when ``None`` is passed
+  as a ``REG_BINARY`` value to SetValueEx.  Patch by John Ehresman.
+
 - Issue #21090: io.FileIO.readall() does not ignore I/O errors anymore. Before,
   it ignored I/O errors if at least the first C call read() succeed.
 
diff --git a/PC/winreg.c b/PC/winreg.c
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -871,8 +871,10 @@
         /* ALSO handle ALL unknown data types here.  Even if we can't
            support it natively, we should handle the bits. */
         default:
-            if (value == Py_None)
+            if (value == Py_None) {
                 *retDataSize = 0;
+                *retDataBuf = NULL;
+            }
             else {
                 Py_buffer view;
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list