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): ...@@ -329,6 +329,15 @@ class LocalWinregTests(BaseWinregTests):
finally: finally:
DeleteKey(HKEY_CURRENT_USER, test_key_name) 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): def test_queryvalueex_return_value(self):
# Test for Issue #16759, return unsigned int from QueryValueEx. # Test for Issue #16759, return unsigned int from QueryValueEx.
# Reg2Py, which gets called by QueryValueEx, was returning a value # Reg2Py, which gets called by QueryValueEx, was returning a value
......
...@@ -657,6 +657,7 @@ Per Øyvind Karlsen ...@@ -657,6 +657,7 @@ Per Øyvind Karlsen
Anton Kasyanov Anton Kasyanov
Lou Kates Lou Kates
Hiroaki Kawai Hiroaki Kawai
Brian Kearns
Sebastien Keim Sebastien Keim
Ryan Kelly Ryan Kelly
Dan Kenigsberg Dan Kenigsberg
......
...@@ -888,7 +888,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) ...@@ -888,7 +888,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
else { else {
void *src_buf; void *src_buf;
PyBufferProcs *pb = value->ob_type->tp_as_buffer; PyBufferProcs *pb = value->ob_type->tp_as_buffer;
if (pb==NULL) { if (pb == NULL || pb->bf_getreadbuffer == NULL) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Objects of type '%s' can not " "Objects of type '%s' can not "
"be used as binary registry values", "be used as binary registry values",
...@@ -896,9 +896,11 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) ...@@ -896,9 +896,11 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
return FALSE; return FALSE;
} }
*retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf); *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
*retDataBuf = (BYTE *)PyMem_NEW(char, if (*retDataSize < 0) {
*retDataSize); return FALSE;
if (*retDataBuf==NULL){ }
*retDataBuf = (BYTE *)PyMem_NEW(char, *retDataSize);
if (*retDataBuf == NULL){
PyErr_NoMemory(); PyErr_NoMemory();
return FALSE; 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