mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	Fix #16759. Convert DWORD registry values using PyLong_FromUnsignedLong.
When converting REG_DWORD registry values into Python ints, the conversion needs to be made from an *unsigned* long to match the DWORD type.
This commit is contained in:
		
							parent
							
								
									12706f2082
								
							
						
					
					
						commit
						172e42295f
					
				
					 3 changed files with 23 additions and 2 deletions
				
			
		| 
						 | 
					@ -335,6 +335,23 @@ class LocalWinregTests(BaseWinregTests):
 | 
				
			||||||
        finally:
 | 
					        finally:
 | 
				
			||||||
            DeleteKey(HKEY_CURRENT_USER, test_key_name)
 | 
					            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")
 | 
					@unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
 | 
				
			||||||
class RemoteWinregTests(BaseWinregTests):
 | 
					class RemoteWinregTests(BaseWinregTests):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,10 @@ What's New in Python 3.2.4
 | 
				
			||||||
Core and Builtins
 | 
					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
 | 
					- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg
 | 
				
			||||||
  when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx.
 | 
					  when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -900,9 +900,9 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
 | 
				
			||||||
    switch (typ) {
 | 
					    switch (typ) {
 | 
				
			||||||
        case REG_DWORD:
 | 
					        case REG_DWORD:
 | 
				
			||||||
            if (retDataSize == 0)
 | 
					            if (retDataSize == 0)
 | 
				
			||||||
                obData = PyLong_FromLong(0);
 | 
					                obData = PyLong_FromUnsignedLong(0);
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                obData = PyLong_FromLong(*(int *)retDataBuf);
 | 
					                obData = PyLong_FromUnsignedLong(*(int *)retDataBuf);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case REG_SZ:
 | 
					        case REG_SZ:
 | 
				
			||||||
        case REG_EXPAND_SZ:
 | 
					        case REG_EXPAND_SZ:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue