[Python-checkins] CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6
Fred L. Drake
python-dev@python.org
2000年6月30日 10:48:54 -0700
Update of /cvsroot/python/python/dist/src/PC
In directory slayer.i.sourceforge.net:/tmp/cvs-serv11047/PC
Modified Files:
msvcrtmodule.c _winreg.c
Log Message:
[*** 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.
Index: msvcrtmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/msvcrtmodule.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** msvcrtmodule.c 1999年02月16日 19:40:02 1.4
--- msvcrtmodule.c 2000年06月30日 17:48:51 1.5
***************
*** 91,95 ****
{
int fd;
! long handle;
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
--- 91,95 ----
{
int fd;
! intptr_t handle;
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
***************
*** 100,104 ****
return PyErr_SetFromErrno(PyExc_IOError);
! return PyInt_FromLong(handle);
}
--- 100,107 ----
return PyErr_SetFromErrno(PyExc_IOError);
! /* 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);
}
Index: _winreg.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/_winreg.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** _winreg.c 2000年06月29日 19:17:04 1.5
--- _winreg.c 2000年06月30日 17:48:51 1.6
***************
*** 593,597 ****
if (PyErr_Occurred())
return FALSE;
- *pHANDLE = (HKEY)PyInt_AsLong(ob);
}
else {
--- 593,596 ----
***************
*** 629,632 ****
--- 628,632 ----
ok = PyHKEY_Close(obHandle);
}
+ #if SIZEOF_LONG >= SIZEOF_HKEY
else if (PyInt_Check(obHandle)) {
long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
***************
*** 635,638 ****
--- 635,646 ----
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 {
PyErr_SetString(
***************
*** 881,891 ****
fixupMultiSZ(str, retDataBuf, retDataSize);
obData = PyList_New(s);
for (index = 0; index < s; index++)
{
PyList_SetItem(obData,
index,
PyUnicode_DecodeMBCS(
(const char *)str[index],
! _mbstrlen(str[index]),
NULL)
);
--- 889,908 ----
fixupMultiSZ(str, retDataBuf, retDataSize);
obData = PyList_New(s);
+ if (obData == NULL)
+ return NULL;
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,
index,
PyUnicode_DecodeMBCS(
(const char *)str[index],
! (int)len,
NULL)
);