summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2014-04-26 14:47:08 (GMT)
committerTim Golden <mail@timgolden.me.uk>2014-04-26 14:47:08 (GMT)
commit3c603f3618fcf7c519e96b9a0d11e2670a47cbb4 (patch)
treebafc044346c12a8b3a2cead74090e60e154e5bcb
parentbe580f2e481f5f129a1e47e436dd7ae54b9f50bd (diff)
downloadcpython-3c603f3618fcf7c519e96b9a0d11e2670a47cbb4.zip
cpython-3c603f3618fcf7c519e96b9a0d11e2670a47cbb4.tar.gz
cpython-3c603f3618fcf7c519e96b9a0d11e2670a47cbb4.tar.bz2
Issue21349 Passing a memoryview to _winreg.SetValueEx now correctly raises a TypeError where it previously crashed the interpreter. Patch by Brian Kearns
-rw-r--r--Lib/test/test_winreg.py9
-rw-r--r--Misc/ACKS1
-rw-r--r--PC/_winreg.c10
3 files changed, 16 insertions, 4 deletions
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
index e05d040..260c224 100644
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -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
diff --git a/Misc/ACKS b/Misc/ACKS
index 9a6f57a..1c40bb3 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -657,6 +657,7 @@ Per Øyvind Karlsen
Anton Kasyanov
Lou Kates
Hiroaki Kawai
+Brian Kearns
Sebastien Keim
Ryan Kelly
Dan Kenigsberg
diff --git a/PC/_winreg.c b/PC/_winreg.c
index 472e84e..f90a282 100644
--- a/PC/_winreg.c
+++ b/PC/_winreg.c
@@ -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;
}