diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2000-08-27 19:15:31 +0000 |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2000-08-27 19:15:31 +0000 |
commit | 5776f5504018fccc3f714f2e0b477ce568eac7bb (patch) | |
tree | 67ab0e5ce1610555bd2bdbdec58e405a05960049 /Python/pythonrun.c | |
parent | f42b40b73307e506433323a6a7a11355c04a7e2b (diff) | |
download | cpython-5776f5504018fccc3f714f2e0b477ce568eac7bb.tar.gz |
implements PyOS_CheckStack for Windows and MSVC. this fixes a
couple of potential stack overflows, including bug #110615.
closes patch #101238
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 8d571c369c..e951ccd1b7 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1165,3 +1165,32 @@ Py_FdIsInteractive(FILE *fp, char *filename) (strcmp(filename, "<stdin>") == 0) || (strcmp(filename, "???") == 0); } + + +#if defined(USE_STACKCHECK) +#if defined(WIN32) && defined(_MSC_VER) + +/* Stack checking for Microsoft C */ + +#include <malloc.h> +#include <excpt.h> + +int +PyOS_CheckStack() +{ + __try { + /* _alloca throws a stack overflow exception if there's + not enough space left on the stack */ + _alloca(PYOS_STACK_MARGIN * sizeof(void*)); + return 0; + } __except (EXCEPTION_EXECUTE_HANDLER) { + /* just ignore all errors */ + } + return 1; +} + +#endif /* WIN32 && _MSC_VER */ + +/* Alternate implementations can be added here... */ + +#endif /* USE_STACKCHECK */ |