New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
winreg.SetValueEx causes crash if value = None #65350
Comments
Here's a small program that crashes Python 3. import winreg
winreg.SetValueEx(winreg.HKEY_CURRENT_USER, 'Value', 0, 3, None) I get a 0xC0000374 exception (STATUS_HEAP_CORRUPTION) when trying to run this. Here's a stack dump: (snip) System is Windows 7 64-bit, with stock x86-64 Python 3.4.0 binaries. Incidentally, I was feeding the 'None' to winreg.SetValueEx because that is the value that winreg.EnumValue returns for zero-length binary values. This is somewhat unexpected; I'd personally prefer to get b'' in that instance. |
In Py2Reg, the REG_BINARY (3) case sets http://hg.python.org/cpython/file/04f714765c13/PC/winreg.c#l766 It doesn't modify *retDataBuf. Then in PySetValueEx, PyMem_DEL is called for the uninitialized address in data: http://hg.python.org/cpython/file/04f714765c13/PC/winreg.c#l1566 Py2Reg in this case could also set |
Here's a simple patch with a test. Oddly, the test doesn't fail before the fix is applied when run with rt.bat, but fails when run directly. |
Patch works on my end. |
Hi. You have some trailing whitespaces in the test file (run make patchcheck or python ../Tools/scripts/patchcheck.py). Except that, looks good to me. |
New changeset f2e6c33ce3e9 by Zachary Ware in branch '2.7': New changeset 0c5a1835af91 by Zachary Ware in branch '3.4': New changeset 21cfbcacf0d8 by Zachary Ware in branch 'default': |
Thanks to Dave for the report, eryksun for the suggestion, and John for the patch! I'm not sure why the test case doesn't fail on a regular test run on Python 3; it looks like BYTE *data starts out as NULL when Python is not in interactive mode, which makes no sense to me. The test case does crash on unpatched 2.7, though, so it's a legitimate test in my view. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: