[*** Not tested as I don't have Windows running right now! ***]
Trent Mick <trentm@activestate.com>: Fix PC/msvcrtmodule.c and PC/winreg.c for Win64. Basically: - sizeof(HKEY) > sizeof(long) on Win64, so use PyLong_FromVoidPtr() instead of PyInt_FromLong() to return HKEY values on Win64 - Check for string overflow of an arbitrary registry value (I know that ensuring that a registry value does not overflow 2**31 characters seems ridiculous but it is *possible*). Closes SourceForge patch #100517.
This commit is contained in:
parent
7efcafb994
commit
25e1726d31
21
PC/_winreg.c
21
PC/_winreg.c
|
@ -592,7 +592,6 @@ PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
|
||||||
*pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
|
*pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
*pHANDLE = (HKEY)PyInt_AsLong(ob);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
|
@ -628,12 +627,21 @@ PyWinObject_CloseHKEY(PyObject *obHandle)
|
||||||
if (PyHKEY_Check(obHandle)) {
|
if (PyHKEY_Check(obHandle)) {
|
||||||
ok = PyHKEY_Close(obHandle);
|
ok = PyHKEY_Close(obHandle);
|
||||||
}
|
}
|
||||||
|
#if SIZEOF_LONG >= SIZEOF_HKEY
|
||||||
else if (PyInt_Check(obHandle)) {
|
else if (PyInt_Check(obHandle)) {
|
||||||
long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
|
long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
|
||||||
ok = (rc == ERROR_SUCCESS);
|
ok = (rc == ERROR_SUCCESS);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
else if (PyLong_Check(obHandle)) {
|
||||||
|
long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
|
||||||
|
ok = (rc == ERROR_SUCCESS);
|
||||||
|
if (!ok)
|
||||||
|
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_TypeError,
|
PyExc_TypeError,
|
||||||
|
@ -880,13 +888,22 @@ Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
|
||||||
|
|
||||||
fixupMultiSZ(str, retDataBuf, retDataSize);
|
fixupMultiSZ(str, retDataBuf, retDataSize);
|
||||||
obData = PyList_New(s);
|
obData = PyList_New(s);
|
||||||
|
if (obData == NULL)
|
||||||
|
return NULL;
|
||||||
for (index = 0; index < s; index++)
|
for (index = 0; index < s; index++)
|
||||||
{
|
{
|
||||||
|
size_t len = _mbstrlen(str[index]);
|
||||||
|
if (len > INT_MAX) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"registry string is too long for a Python string");
|
||||||
|
Py_DECREF(obData);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
PyList_SetItem(obData,
|
PyList_SetItem(obData,
|
||||||
index,
|
index,
|
||||||
PyUnicode_DecodeMBCS(
|
PyUnicode_DecodeMBCS(
|
||||||
(const char *)str[index],
|
(const char *)str[index],
|
||||||
_mbstrlen(str[index]),
|
(int)len,
|
||||||
NULL)
|
NULL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
|
||||||
static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
|
static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
long handle;
|
intptr_t handle;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
|
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -99,7 +99,10 @@ static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
|
||||||
if (handle == -1)
|
if (handle == -1)
|
||||||
return PyErr_SetFromErrno(PyExc_IOError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
|
||||||
return PyInt_FromLong(handle);
|
/* technically 'handle' is not a pointer, but a integer as
|
||||||
|
large as a pointer, Python's *VoidPtr interface is the
|
||||||
|
most appropriate here */
|
||||||
|
return PyLong_FromVoidPtr((void*)handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Console I/O */
|
/* Console I/O */
|
||||||
|
|
Loading…
Reference in New Issue