]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
implements PyOS_CheckStack for Windows and MSVC. this fixes a
authorFredrik Lundh <fredrik@pythonware.com>
Sun, 27 Aug 2000 19:15:31 +0000 (19:15 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Sun, 27 Aug 2000 19:15:31 +0000 (19:15 +0000)
couple of potential stack overflows, including bug #110615.

closes patch #101238

Include/pythonrun.h
Python/pythonrun.c

index c217570dcf1306359e95983ba551204851941b33..05287021aa757c0a8277231ed04219b655593484 100644 (file)
@@ -87,8 +87,20 @@ DL_IMPORT(void) PyOS_FiniInterrupts(void);
 DL_IMPORT(char *) PyOS_Readline(char *);
 extern DL_IMPORT(int) (*PyOS_InputHook)(void);
 extern DL_IMPORT(char) *(*PyOS_ReadlineFunctionPointer)(char *);
+
+/* Stack size, in "pointers" (so we get extra safety margins
+   on 64-bit platforms).  On a 32-bit platform, this translates
+   to a 8k margin. */
+#define PYOS_STACK_MARGIN 2048
+
+#if defined(WIN32) && defined(_MSC_VER)
+/* Enable stack checking under Microsoft C */
+#define USE_STACKCHECK
+#endif
+
 #ifdef USE_STACKCHECK
-int PyOS_CheckStack(void);             /* Check that we aren't overflowing our stack */
+/* Check that we aren't overflowing our stack */
+DL_IMPORT(int) PyOS_CheckStack(void);
 #endif
 
 #ifdef __cplusplus
index 8d571c369c06e5e4ad71cbfbf93cac956e9db224..e951ccd1b7ac2cb3b129f714d283988e3bcad982 100644 (file)
@@ -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 */