home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.2.230 < prev    next >
Encoding:
Internet Message Format  |  2004-02-02  |  8.1 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.230 (extra)
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.2.230 (extra)
  11. Problem:    Win32: a complex pattern may cause a crash.
  12. Solution:   Use __try and __except to catch the exception and handle it
  13.         gracefully, when possible.  Add myresetstkoflw() to reset the
  14.         stack overflow. (Benjamin Peterson)
  15. Files:        src/Make_bc5.mak, src/os_mswin.c src/os_win32.c, src/os_win32.h,
  16.         src/proto/os_win32.pro, src/regexp.c
  17.  
  18.  
  19. *** ../vim-6.2.229/src/Make_bc5.mak    Tue Feb  3 16:20:37 2004
  20. --- src/Make_bc5.mak    Tue Feb  3 10:47:26 2004
  21. ***************
  22. *** 488,494 ****
  23.   CC   = $(BOR)\BIN\Bcc32
  24.   LFLAGS    = -OS -Tpe -c -m -L$(LIB) $(DEBUG_FLAG) $(LINK2)
  25.   LFLAGSDLL  = -Tpd -c -m -L$(LIB) $(DEBUG_FLAG) $(LINK2)
  26. ! CFLAGS = -w-aus -w-par -w-pch -I$(INCLUDE) -d -x- -RT- -k- -Oi $(HEADERS) -f-
  27.   !endif
  28.   
  29.   CC1 = -c
  30. --- 488,494 ----
  31.   CC   = $(BOR)\BIN\Bcc32
  32.   LFLAGS    = -OS -Tpe -c -m -L$(LIB) $(DEBUG_FLAG) $(LINK2)
  33.   LFLAGSDLL  = -Tpd -c -m -L$(LIB) $(DEBUG_FLAG) $(LINK2)
  34. ! CFLAGS = -w-aus -w-par -w-pch -I$(INCLUDE) -d -RT- -k- -Oi $(HEADERS) -f-
  35.   !endif
  36.   
  37.   CC1 = -c
  38. *** ../vim-6.2.229/src/os_mswin.c    Sun Oct 12 16:42:14 2003
  39. --- src/os_mswin.c    Sun Feb  1 17:18:09 2004
  40. ***************
  41. *** 738,743 ****
  42. --- 738,747 ----
  43.       // If the handle is valid, try to get the function address.
  44.       if (hinstLib != NULL)
  45.       {
  46. + #ifdef HAVE_TRY_EXCEPT
  47. +     __try
  48. +     {
  49. + #endif
  50.       if (argstring != NULL)
  51.       {
  52.           /* Call with string argument */
  53. ***************
  54. *** 782,787 ****
  55. --- 786,801 ----
  56.           if (*string_result != NULL)
  57.           mch_memmove(*string_result, retval_str, len);
  58.       }
  59. + #ifdef HAVE_TRY_EXCEPT
  60. +     }
  61. +     __except(EXCEPTION_EXECUTE_HANDLER)
  62. +     {
  63. +         if (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW)
  64. +         RESETSTKOFLW();
  65. +         fRunTimeLinkSuccess = 0;
  66. +     }
  67. + #endif
  68.   
  69.       // Free the DLL module.
  70.       (void)FreeLibrary(hinstLib);
  71. *** ../vim-6.2.229/src/os_win32.c    Sun Oct 26 20:15:06 2003
  72. --- src/os_win32.c    Sun Feb  1 17:37:49 2004
  73. ***************
  74. *** 4202,4204 ****
  75. --- 4203,4312 ----
  76.   {
  77.       return copy_infostreams(from, to);
  78.   }
  79. + #if defined(MYRESETSTKOFLW) || defined(PROTO)
  80. + /*
  81. +  * Recreate a destroyed stack guard page in win32.
  82. +  * Written by Benjamin Peterson.
  83. +  */
  84. + /* These magic numbers are from the MS header files */
  85. + #define MIN_STACK_WIN9X 17
  86. + #define MIN_STACK_WINNT 2
  87. + /*
  88. +  * This function does the same thing as _resetstkoflw(), which is only
  89. +  * available in DevStudio .net and later.
  90. +  * Returns 0 for failure, 1 for success.
  91. +  */
  92. +     int
  93. + myresetstkoflw(void)
  94. + {
  95. +     BYTE    *pStackPtr;
  96. +     BYTE    *pGuardPage;
  97. +     BYTE    *pStackBase;
  98. +     BYTE    *pLowestPossiblePage;
  99. +     MEMORY_BASIC_INFORMATION mbi;
  100. +     SYSTEM_INFO si;
  101. +     DWORD    nPageSize;
  102. +     DWORD    dummy;
  103. +     /* This code will not work on win32s. */
  104. +     PlatformId();
  105. +     if (g_PlatformId == VER_PLATFORM_WIN32s)
  106. +     return 0;
  107. +     /* We need to know the system page size. */
  108. +     GetSystemInfo(&si);
  109. +     nPageSize = si.dwPageSize;
  110. +     /* ...and the current stack pointer */
  111. +     pStackPtr = (BYTE*)_alloca(1);
  112. +     /* ...and the base of the stack. */
  113. +     if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0)
  114. +         return 0;
  115. +     pStackBase = (BYTE*)mbi.AllocationBase;
  116. +     /* ...and the page thats min_stack_req pages away from stack base; this is
  117. +      * the lowest page we could use. */
  118. +     pLowestPossiblePage = pStackBase + ((g_PlatformId == VER_PLATFORM_WIN32_NT)
  119. +                  ? MIN_STACK_WINNT : MIN_STACK_WIN9X) * nPageSize;
  120. +     /* On Win95, we want the next page down from the end of the stack. */
  121. +     if (g_PlatformId == VER_PLATFORM_WIN32_WINDOWS)
  122. +     {
  123. +     /* Find the page that's only 1 page down from the page that the stack
  124. +      * ptr is in. */
  125. +         pGuardPage = (BYTE*)((DWORD)nPageSize * (((DWORD)pStackPtr
  126. +                             / (DWORD)nPageSize) - 1));
  127. +         if (pGuardPage < pLowestPossiblePage)
  128. +             return 0;
  129. +     /* Apply the noaccess attribute to the page -- there's no guard
  130. +      * attribute in win95-type OSes. */
  131. +         if (!VirtualProtect(pGuardPage, nPageSize, PAGE_NOACCESS, &dummy))
  132. +             return 0;
  133. +     }
  134. +     else
  135. +     {
  136. +     /* On NT, however, we want the first committed page in the stack Start
  137. +      * at the stack base and move forward through memory until we find a
  138. +      * committed block. */
  139. +         BYTE *pBlock = pStackBase;
  140. +         while (1)
  141. +         {
  142. +             if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0)
  143. +                 return 0;
  144. +             pBlock += mbi.RegionSize;
  145. +             if (mbi.State & MEM_COMMIT)
  146. +                 break;
  147. +         }
  148. +         /* mbi now describes the first committed block in the stack. */
  149. +         if (mbi.Protect & PAGE_GUARD)
  150. +             return 1;
  151. +         /* decide where the guard page should start */
  152. +         if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage)
  153. +             pGuardPage = pLowestPossiblePage;
  154. +         else
  155. +             pGuardPage = (BYTE*)mbi.BaseAddress;
  156. +         /* allocate the guard page */
  157. +         if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE))
  158. +             return 0;
  159. +         /* apply the guard attribute to the page */
  160. +         if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD,
  161. +                                       &dummy))
  162. +             return 0;
  163. +     }
  164. +     return 1;
  165. + }
  166. + #endif
  167. *** ../vim-6.2.229/src/os_win32.h    Sun Oct 12 16:42:14 2003
  168. --- src/os_win32.h    Sun Feb  1 17:49:34 2004
  169. ***************
  170. *** 117,122 ****
  171. --- 117,135 ----
  172.   # define DFLT_MAXMEMTOT    (5*1024)    /* use up to 5 Mbyte for Vim */
  173.   #endif
  174.   
  175. + #if defined(_MSC_VER) || defined(__BORLANDC__)
  176. +     /* Support for __try / __except.  All versions of MSVC and Borland C are
  177. +      * expected to have this.  Any other compilers that support it? */
  178. + # define HAVE_TRY_EXCEPT 1
  179. + # include <malloc.h>        /* for _resetstkoflw() */
  180. + # if defined(_MSC_VER) && (_MSC_VER >= 1300)
  181. + #  define RESETSTKOFLW _resetstkoflw
  182. + # else
  183. + #  define RESETSTKOFLW myresetstkoflw
  184. + #  define MYRESETSTKOFLW
  185. + # endif
  186. + #endif
  187.   /*
  188.    * Some simple debugging macros that look and behave a lot like their
  189.    * namesakes in MFC.
  190. *** ../vim-6.2.229/src/proto/os_win32.pro    Sun Jun  1 12:26:30 2003
  191. --- src/proto/os_win32.pro    Sun Feb  1 17:32:46 2004
  192. ***************
  193. *** 41,44 ****
  194. --- 41,45 ----
  195.   char *default_shell __ARGS((void));
  196.   int mch_access __ARGS((char *n, int p));
  197.   int mch_copy_file_attribute __ARGS((char_u *from, char_u *to));
  198. + int myresetstkoflw __ARGS((void));
  199.   /* vim: set ft=c : */
  200. *** ../vim-6.2.229/src/regexp.c    Sat Sep 27 19:36:47 2003
  201. --- src/regexp.c    Sun Feb  1 17:50:16 2004
  202. ***************
  203. *** 2784,2789 ****
  204. --- 2784,2795 ----
  205.   #endif
  206.   
  207.       reg_tofree = NULL;
  208. + #ifdef HAVE_TRY_EXCEPT
  209. +     __try
  210. +     {
  211. + #endif
  212.   #ifdef HAVE_SETJMP_H
  213.       /*
  214.        * Matching with a regexp may cause a very deep recursive call of
  215. ***************
  216. *** 2939,2944 ****
  217. --- 2945,2965 ----
  218.   
  219.       if (out_of_stack)
  220.       EMSG(_("E363: pattern caused out-of-stack error"));
  221. + #ifdef HAVE_TRY_EXCEPT
  222. +     }
  223. +     __except(EXCEPTION_EXECUTE_HANDLER)
  224. +     {
  225. +     if (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW)
  226. +     {
  227. +         RESETSTKOFLW();
  228. +         EMSG(_("E363: pattern caused out-of-stack error"));
  229. +     }
  230. +     else
  231. +         EMSG(_("E361: Crash intercepted; regexp too complex?"));
  232. +     retval = 0L;
  233. +     }
  234. + #endif
  235.   
  236.   theend:
  237.       /* Didn't find a match. */
  238. *** ../vim-6.2.229/src/version.c    Tue Feb  3 16:33:22 2004
  239. --- src/version.c    Tue Feb  3 16:52:46 2004
  240. ***************
  241. *** 639,640 ****
  242. --- 639,642 ----
  243.   {   /* Add new patch number below this line */
  244. + /**/
  245. +     230,
  246.   /**/
  247.  
  248. -- 
  249. What a wonderfully exciting cough!  Do you mind if I join you?
  250.         -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
  251.  
  252.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  253. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  254. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  255.  \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///
  256.