Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue21151

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:winreg.SetValueEx causes crash if value = None
Type:crashStage:resolved
Components:Extension Modules, WindowsVersions:Python 3.4, Python 3.5, Python 2.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: zach.wareNosy List: Claudiu.Popa, dmo2118, eryksun, jpe, python-dev, steve.dower, stutzbach, zach.ware
Priority:normalKeywords:patch

Created on2014-04-04 03:17 bydmo2118, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
fix-none-value.diffjpe,2014-04-14 19:00review
Messages (7)
msg215486 -(view)Author: Dave Odell (dmo2118)Date: 2014-04-04 03:17
Here's a small program that crashes Python 3.import winregwinreg.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)ntdll.dll!RtlpLogHeapFailure+0xa4ntdll.dll! ?? ::FNODOBFM::`string'+0x10c7ckernel32.dll!HeapFree+0xaMSVCR100.dll!free+0x1cpython34.dll!PySetValueEx+0xf8python34.dll!PyCFunction_Call+0x12dpython34.dll!call_function+0x2abpython34.dll!PyEval_EvalFrameEx+0x2259python34.dll!PyEval_EvalCodeEx+0x65cpython34.dll!PyEval_EvalCode+0x2epython34.dll!builtin_exec+0x1b5python34.dll!PyCFunction_Call+0x12dpython34.dll!call_function+0x2abpython34.dll!PyEval_EvalFrameEx+0x2259python34.dll!PyEval_EvalCodeEx+0x65cpython34.dll!function_call+0x15dpython34.dll!PyObject_Call+0x61python34.dll!ext_do_call+0x2abpython34.dll!PyEval_EvalFrameEx+0x22fepython34.dll!PyEval_EvalCodeEx+0x65cpython34.dll!fast_function+0x14dpython34.dll!call_function+0x311python34.dll!PyEval_EvalFrameEx+0x2259python34.dll!PyEval_EvalCodeEx+0x65cpython34.dll!PyEval_EvalCode+0x2epython34.dll!run_mod+0x53python34.dll!PyRun_StringFlags+0x9cpython34.dll!PyRun_SimpleStringFlags+0x41python34.dll!run_command+0x55python34.dll!Py_Main+0x683pythonw.exe!__tmainCRTStartup+0x166kernel32.dll!BaseThreadInitThunk+0xdntdll.dll!RtlUserThreadStart+0x1dSystem 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.
msg215490 -(view)Author: Eryk Sun (eryksun)*(Python triager)Date: 2014-04-04 05:28
In Py2Reg, the REG_BINARY (3) case sets `*retDataSize = 0` when the value is None:http://hg.python.org/cpython/file/04f714765c13/PC/winreg.c#l766It 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#l1566Py2Reg in this case could also set `*retDataBuf = NULL`. RegSetValueEx allows lpData to be NULL when cbData is 0.http://msdn.microsoft.com/en-us/library/ms724923
msg216173 -(view)Author: John Ehresman (jpe)*Date: 2014-04-14 19:00
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.
msg216637 -(view)Author: Dave Odell (dmo2118)Date: 2014-04-17 01:50
Patch works on my end.
msg220579 -(view)Author: PCManticore (Claudiu.Popa)*(Python triager)Date: 2014-06-14 20:59
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.
msg222196 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-07-03 16:04
New changesetf2e6c33ce3e9 by Zachary Ware in branch '2.7':Issue#21151: Fixed a segfault in the _winreg module.http://hg.python.org/cpython/rev/f2e6c33ce3e9New changeset0c5a1835af91 by Zachary Ware in branch '3.4':Issue#21151: Fixed a segfault in the winreg module.http://hg.python.org/cpython/rev/0c5a1835af91New changeset21cfbcacf0d8 by Zachary Ware in branch 'default':Closes#21151: Merge with 3.4http://hg.python.org/cpython/rev/21cfbcacf0d8
msg222198 -(view)Author: Zachary Ware (zach.ware)*(Python committer)Date: 2014-07-03 16:08
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.
History
DateUserActionArgs
2022-04-11 14:58:01adminsetgithub: 65350
2014-07-03 16:08:31zach.waresetpriority: high -> normal
versions: + Python 2.7, Python 3.4
messages: +msg222198

assignee:zach.ware
components: + Extension Modules, - Library (Lib)
2014-07-03 16:04:14python-devsetstatus: open -> closed

nosy: +python-dev
messages: +msg222196

resolution: fixed
stage: commit review -> resolved
2014-07-03 09:38:33Claudiu.Popasetpriority: normal -> high
nosy: +zach.ware,steve.dower
2014-06-27 05:47:02Claudiu.Popasetstage: patch review -> commit review
2014-06-14 20:59:14Claudiu.Popasetversions: + Python 3.5, - Python 3.4
nosy: +Claudiu.Popa

messages: +msg220579

stage: patch review
2014-04-17 01:50:06dmo2118setmessages: +msg216637
2014-04-14 19:00:48jpesetfiles: +fix-none-value.diff

nosy: +jpe
messages: +msg216173

keywords: +patch
2014-04-04 05:28:56eryksunsetnosy: +eryksun
messages: +msg215490
2014-04-04 03:17:01dmo2118create
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp