diff options
author | Shreyan Avigyan <shreyan.avigyan@gmail.com> | 2022-12-09 12:47:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-09 12:47:18 (GMT) |
commit | a29a7b9b786d6b928c4bb4e6e683a3788e3ab1c1 (patch) | |
tree | d8af5c025584ef659d4dff7bdd485d7ea4a4bb9c /PC/winreg.c | |
parent | fb713b21833a17cba8022af0fa4c486512157d4b (diff) | |
download | cpython-a29a7b9b786d6b928c4bb4e6e683a3788e3ab1c1.zip cpython-a29a7b9b786d6b928c4bb4e6e683a3788e3ab1c1.tar.gz cpython-a29a7b9b786d6b928c4bb4e6e683a3788e3ab1c1.tar.bz2 |
bpo-43984: Allow winreg.SetValueEx to set -1 without treating it as an error (GH-25775)
Diffstat (limited to 'PC/winreg.c')
-rw-r--r-- | PC/winreg.c | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/PC/winreg.c b/PC/winreg.c index df34e8c..63b37be 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -561,42 +561,54 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) { Py_ssize_t i,j; switch (typ) { - case REG_DWORD: - if (value != Py_None && !PyLong_Check(value)) - return FALSE; - *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); - if (*retDataBuf == NULL){ - PyErr_NoMemory(); - return FALSE; - } - *retDataSize = sizeof(DWORD); - if (value == Py_None) { - DWORD zero = 0; - memcpy(*retDataBuf, &zero, sizeof(DWORD)); - } - else { - DWORD d = PyLong_AsUnsignedLong(value); + case REG_DWORD: + { + if (value != Py_None && !PyLong_Check(value)) { + return FALSE; + } + DWORD d; + if (value == Py_None) { + d = 0; + } + else if (PyLong_Check(value)) { + d = PyLong_AsUnsignedLong(value); + if (d == (DWORD)(-1) && PyErr_Occurred()) { + return FALSE; + } + } + *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); + if (*retDataBuf == NULL) { + PyErr_NoMemory(); + return FALSE; + } memcpy(*retDataBuf, &d, sizeof(DWORD)); + *retDataSize = sizeof(DWORD); + break; } - break; - case REG_QWORD: - if (value != Py_None && !PyLong_Check(value)) - return FALSE; - *retDataBuf = (BYTE *)PyMem_NEW(DWORD64, 1); - if (*retDataBuf == NULL){ - PyErr_NoMemory(); - return FALSE; - } - *retDataSize = sizeof(DWORD64); - if (value == Py_None) { - DWORD64 zero = 0; - memcpy(*retDataBuf, &zero, sizeof(DWORD64)); - } - else { - DWORD64 d = PyLong_AsUnsignedLongLong(value); + case REG_QWORD: + { + if (value != Py_None && !PyLong_Check(value)) { + return FALSE; + } + DWORD64 d; + if (value == Py_None) { + d = 0; + } + else if (PyLong_Check(value)) { + d = PyLong_AsUnsignedLongLong(value); + if (d == (DWORD64)(-1) && PyErr_Occurred()) { + return FALSE; + } + } + *retDataBuf = (BYTE *)PyMem_NEW(DWORD64, 1); + if (*retDataBuf == NULL) { + PyErr_NoMemory(); + return FALSE; + } memcpy(*retDataBuf, &d, sizeof(DWORD64)); + *retDataSize = sizeof(DWORD64); + break; } - break; case REG_SZ: case REG_EXPAND_SZ: { |