Skip to content

Commit

Permalink
Fix python#16759. Convert DWORD registry values using unsigned long.
Browse files Browse the repository at this point in the history
When converting REG_DWORD registry values into Python, the conversion
needs to be made from an *unsigned* long (k instead of i) to match the
DWORD type.
  • Loading branch information
briancurtin committed Dec 27, 2012
1 parent a0b7e9c commit 33e05e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Lib/test/test_winreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ def test_setvalueex_value_range(self):
finally:
DeleteKey(HKEY_CURRENT_USER, test_key_name)

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
# PyLong_FromUnsignedLong to match DWORD's size.
try:
with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
self.assertNotEqual(ck.handle, 0)
test_val = 0x80000000
SetValueEx(ck, "test_name", None, REG_DWORD, test_val)
ret_val, ret_type = QueryValueEx(ck, "test_name")
self.assertEqual(ret_type, REG_DWORD)
self.assertEqual(ret_val, test_val)
finally:
DeleteKey(HKEY_CURRENT_USER, test_key_name)



@unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
class RemoteWinregTests(BaseWinregTests):
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ What's New in Python 2.7.4
Core and Builtins
-----------------

- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
when retreiving a REG_DWORD value. This corrects functions like
winreg.QueryValueEx that may have been returning truncated values.

- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg
when passed a REG_DWORD value. Fixes ValueError in winreg.SetValueEx when
given a long.
Expand Down
4 changes: 2 additions & 2 deletions PC/_winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
switch (typ) {
case REG_DWORD:
if (retDataSize == 0)
obData = Py_BuildValue("i", 0);
obData = Py_BuildValue("k", 0);
else
obData = Py_BuildValue("i",
obData = Py_BuildValue("k",
*(int *)retDataBuf);
break;
case REG_SZ:
Expand Down

0 comments on commit 33e05e7

Please sign in to comment.