Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
tests.
This commit is contained in:
parent
6f2a5efec9
commit
582acece2e
|
@ -2876,7 +2876,7 @@ exec_statement(f, prog, globals, locals)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *s = PyString_AsString(prog);
|
char *s = PyString_AsString(prog);
|
||||||
if ((int)strlen(s) != PyString_Size(prog)) {
|
if (strlen(s) != (size_t)PyString_Size(prog)) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"embedded '\\0' in exec string");
|
"embedded '\\0' in exec string");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -83,11 +83,16 @@ static
|
||||||
PyObject *normalizestring(const char *string)
|
PyObject *normalizestring(const char *string)
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
int len = strlen(string);
|
size_t len = strlen(string);
|
||||||
char *p;
|
char *p;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
v = PyString_FromStringAndSize(NULL, len);
|
if (len > INT_MAX) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError, "string is too large");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = PyString_FromStringAndSize(NULL, (int)len);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = PyString_AS_STRING(v);
|
p = PyString_AS_STRING(v);
|
||||||
|
|
|
@ -265,8 +265,8 @@ PyCode_New(argcount, nlocals, stacksize, flags,
|
||||||
if (!PyString_Check(v))
|
if (!PyString_Check(v))
|
||||||
continue;
|
continue;
|
||||||
p = PyString_AsString(v);
|
p = PyString_AsString(v);
|
||||||
if ((int)strspn(p, NAME_CHARS)
|
if (strspn(p, NAME_CHARS)
|
||||||
!= PyString_Size(v))
|
!= (size_t)PyString_Size(v))
|
||||||
continue;
|
continue;
|
||||||
PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
|
PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ com_error(c, exc, msg)
|
||||||
PyObject *exc;
|
PyObject *exc;
|
||||||
char *msg;
|
char *msg;
|
||||||
{
|
{
|
||||||
int n = strlen(msg);
|
size_t n = strlen(msg);
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
char buffer[30];
|
char buffer[30];
|
||||||
char *s;
|
char *s;
|
||||||
|
@ -720,12 +720,12 @@ com_mangle(c, name, buffer, maxlen)
|
||||||
struct compiling *c;
|
struct compiling *c;
|
||||||
char *name;
|
char *name;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int maxlen;
|
size_t maxlen;
|
||||||
{
|
{
|
||||||
/* Name mangling: __private becomes _classname__private.
|
/* Name mangling: __private becomes _classname__private.
|
||||||
This is independent from how the name is used. */
|
This is independent from how the name is used. */
|
||||||
char *p;
|
char *p;
|
||||||
int nlen, plen;
|
size_t nlen, plen;
|
||||||
nlen = strlen(name);
|
nlen = strlen(name);
|
||||||
if (nlen+2 >= maxlen)
|
if (nlen+2 >= maxlen)
|
||||||
return 0; /* Don't mangle __extremely_long_names */
|
return 0; /* Don't mangle __extremely_long_names */
|
||||||
|
@ -761,7 +761,7 @@ com_addopnamestr(c, op, name)
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
if (name != NULL && name[0] == '_' && name[1] == '_' &&
|
if (name != NULL && name[0] == '_' && name[1] == '_' &&
|
||||||
c->c_private != NULL &&
|
c->c_private != NULL &&
|
||||||
com_mangle(c, name, buffer, (int)sizeof(buffer)))
|
com_mangle(c, name, buffer, sizeof(buffer)))
|
||||||
name = buffer;
|
name = buffer;
|
||||||
#endif
|
#endif
|
||||||
if (name == NULL || (v = PyString_InternFromString(name)) == NULL) {
|
if (name == NULL || (v = PyString_InternFromString(name)) == NULL) {
|
||||||
|
@ -883,7 +883,7 @@ parsestr(s)
|
||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
int len;
|
size_t len;
|
||||||
char *buf;
|
char *buf;
|
||||||
char *p;
|
char *p;
|
||||||
char *end;
|
char *end;
|
||||||
|
@ -908,6 +908,10 @@ parsestr(s)
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
|
if (len > INT_MAX) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError, "string to parse is too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (s[--len] != quote) {
|
if (s[--len] != quote) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2201,7 +2205,7 @@ com_global_stmt(c, n)
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
if (s != NULL && s[0] == '_' && s[1] == '_' &&
|
if (s != NULL && s[0] == '_' && s[1] == '_' &&
|
||||||
c->c_private != NULL &&
|
c->c_private != NULL &&
|
||||||
com_mangle(c, s, buffer, (int)sizeof(buffer)))
|
com_mangle(c, s, buffer, sizeof(buffer)))
|
||||||
s = buffer;
|
s = buffer;
|
||||||
#endif
|
#endif
|
||||||
if (PyDict_GetItemString(c->c_locals, s) != NULL) {
|
if (PyDict_GetItemString(c->c_locals, s) != NULL) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
|
||||||
"DLL load failed with error code %d",
|
"DLL load failed with error code %d",
|
||||||
errorCode);
|
errorCode);
|
||||||
} else {
|
} else {
|
||||||
int len;
|
size_t len;
|
||||||
/* For some reason a \r\n
|
/* For some reason a \r\n
|
||||||
is appended to the text */
|
is appended to the text */
|
||||||
if (theLength >= 2 &&
|
if (theLength >= 2 &&
|
||||||
|
|
|
@ -62,7 +62,7 @@ getcwd(buf, size)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = getwd(localbuf);
|
ret = getwd(localbuf);
|
||||||
if (ret != NULL && strlen(localbuf) >= size) {
|
if (ret != NULL && strlen(localbuf) >= (size_t)size) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,8 +355,15 @@ do_mkvalue(p_format, p_va)
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (n < 0)
|
if (n < 0) {
|
||||||
n = strlen(str);
|
size_t m = strlen(str);
|
||||||
|
if (m > INT_MAX) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"string too long for Python string");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
n = (int)m;
|
||||||
|
}
|
||||||
v = PyString_FromStringAndSize(str, n);
|
v = PyString_FromStringAndSize(str, n);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -504,7 +504,7 @@ _PySys_Init()
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
#ifdef MS_COREDLL
|
#ifdef MS_COREDLL
|
||||||
PyDict_SetItemString(sysdict, "dllhandle",
|
PyDict_SetItemString(sysdict, "dllhandle",
|
||||||
v = PyInt_FromLong((int)PyWin_DLLhModule));
|
v = PyLong_FromVoidPtr(PyWin_DLLhModule));
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
PyDict_SetItemString(sysdict, "winver",
|
PyDict_SetItemString(sysdict, "winver",
|
||||||
v = PyString_FromString(PyWin_DLLVersionString));
|
v = PyString_FromString(PyWin_DLLVersionString));
|
||||||
|
|
|
@ -101,6 +101,9 @@ BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex)
|
||||||
return mutex->hevent != NULL ; /* TRUE if the mutex is created */
|
return mutex->hevent != NULL ; /* TRUE if the mutex is created */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef InterlockedCompareExchange
|
||||||
|
#undef InterlockedCompareExchange
|
||||||
|
#endif
|
||||||
#define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand)))
|
#define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand)))
|
||||||
|
|
||||||
VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
|
VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
|
||||||
|
@ -179,7 +182,7 @@ static void PyThread__init_thread(void)
|
||||||
*/
|
*/
|
||||||
int PyThread_start_new_thread(void (*func)(void *), void *arg)
|
int PyThread_start_new_thread(void (*func)(void *), void *arg)
|
||||||
{
|
{
|
||||||
long rv;
|
INT_PTR rv;
|
||||||
int success = 0;
|
int success = 0;
|
||||||
|
|
||||||
dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
|
dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
|
||||||
|
@ -190,7 +193,7 @@ int PyThread_start_new_thread(void (*func)(void *), void *arg)
|
||||||
|
|
||||||
if (rv != -1) {
|
if (rv != -1) {
|
||||||
success = 1;
|
success = 1;
|
||||||
dprintf(("%ld: PyThread_start_new_thread succeeded: %ld\n", PyThread_get_thread_ident(), rv));
|
dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", PyThread_get_thread_ident(), rv));
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -166,7 +166,7 @@ tb_displayline(f, filename, lineno, name)
|
||||||
path = PySys_GetObject("path");
|
path = PySys_GetObject("path");
|
||||||
if (path != NULL && PyList_Check(path)) {
|
if (path != NULL && PyList_Check(path)) {
|
||||||
int npath = PyList_Size(path);
|
int npath = PyList_Size(path);
|
||||||
int taillen = strlen(tail);
|
size_t taillen = strlen(tail);
|
||||||
char namebuf[MAXPATHLEN+1];
|
char namebuf[MAXPATHLEN+1];
|
||||||
for (i = 0; i < npath; i++) {
|
for (i = 0; i < npath; i++) {
|
||||||
PyObject *v = PyList_GetItem(path, i);
|
PyObject *v = PyList_GetItem(path, i);
|
||||||
|
@ -175,12 +175,12 @@ tb_displayline(f, filename, lineno, name)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (PyString_Check(v)) {
|
if (PyString_Check(v)) {
|
||||||
int len;
|
size_t len;
|
||||||
len = PyString_Size(v);
|
len = PyString_Size(v);
|
||||||
if (len + 1 + taillen >= MAXPATHLEN)
|
if (len + 1 + taillen >= MAXPATHLEN)
|
||||||
continue; /* Too long */
|
continue; /* Too long */
|
||||||
strcpy(namebuf, PyString_AsString(v));
|
strcpy(namebuf, PyString_AsString(v));
|
||||||
if ((int)strlen(namebuf) != len)
|
if (strlen(namebuf) != len)
|
||||||
continue; /* v contains '\0' */
|
continue; /* v contains '\0' */
|
||||||
if (len > 0 && namebuf[len-1] != SEP)
|
if (len > 0 && namebuf[len-1] != SEP)
|
||||||
namebuf[len++] = SEP;
|
namebuf[len++] = SEP;
|
||||||
|
|
Loading…
Reference in New Issue