Commit 3c603f36 authored by Tim Golden's avatar Tim Golden

Issue21349 Passing a memoryview to _winreg.SetValueEx now correctly raises a...

Issue21349 Passing a memoryview to _winreg.SetValueEx now correctly raises a TypeError where it previously crashed the interpreter. Patch by Brian Kearns
parent be580f2e
......@@ -329,6 +329,15 @@ class LocalWinregTests(BaseWinregTests):
finally:
DeleteKey(HKEY_CURRENT_USER, test_key_name)
def test_setvalueex_with_memoryview(self):
try:
with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
self.assertNotEqual(ck.handle, 0)
with self.assertRaises(TypeError):
SetValueEx(ck, "test_name", None, REG_BINARY, memoryview('val'))
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
......
......@@ -657,6 +657,7 @@ Per Øyvind Karlsen
Anton Kasyanov
Lou Kates
Hiroaki Kawai
Brian Kearns
Sebastien Keim
Ryan Kelly
Dan Kenigsberg
......
......@@ -888,7 +888,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
else {
void *src_buf;
PyBufferProcs *pb = value->ob_type->tp_as_buffer;
if (pb==NULL) {
if (pb == NULL || pb->bf_getreadbuffer == NULL) {
PyErr_Format(PyExc_TypeError,
"Objects of type '%s' can not "
"be used as binary registry values",
......@@ -896,9 +896,11 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
return FALSE;
}
*retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
*retDataBuf = (BYTE *)PyMem_NEW(char,
*retDataSize);
if (*retDataBuf==NULL){
if (*retDataSize < 0) {
return FALSE;
}
*retDataBuf = (BYTE *)PyMem_NEW(char, *retDataSize);
if (*retDataBuf == NULL){
PyErr_NoMemory();
return FALSE;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment