a8d4498
To: vim-dev@vim.org
a8d4498
Subject: Patch 7.3.009
a8d4498
Fcc: outbox
a8d4498
From: Bram Moolenaar <Bram@moolenaar.net>
a8d4498
Mime-Version: 1.0
a8d4498
Content-Type: text/plain; charset=UTF-8
a8d4498
Content-Transfer-Encoding: 8bit
a8d4498
------------
a8d4498
a8d4498
Patch 7.3.009
a8d4498
Problem:    Win32: Crash on Windows when using a bad argument for strftime().
a8d4498
	    (Christian Brabandt)
a8d4498
Solution:   Use the bad_param_handler(). (Mike Williams)
a8d4498
Files:	    src/os_win32.c
a8d4498
a8d4498
a8d4498
*** ../vim-7.3.008/src/os_win32.c	2010-08-15 21:57:27.000000000 +0200
a8d4498
--- src/os_win32.c	2010-09-21 17:02:54.000000000 +0200
a8d4498
***************
a8d4498
*** 1615,1620 ****
a8d4498
--- 1615,1649 ----
a8d4498
      return TRUE;
a8d4498
  }
a8d4498
  
a8d4498
+ #if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \
a8d4498
+         __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400)
a8d4498
+ /*
a8d4498
+  * Bad parameter handler.
a8d4498
+  *
a8d4498
+  * Certain MS CRT functions will intentionally crash when passed invalid
a8d4498
+  * parameters to highlight possible security holes.  Setting this function as
a8d4498
+  * the bad parameter handler will prevent the crash.
a8d4498
+  *
a8d4498
+  * In debug builds the parameters contain CRT information that might help track
a8d4498
+  * down the source of a problem, but in non-debug builds the arguments are all
a8d4498
+  * NULL/0.  Debug builds will also produce assert dialogs from the CRT, it is
a8d4498
+  * worth allowing these to make debugging of issues easier.
a8d4498
+  */
a8d4498
+     static void
a8d4498
+ bad_param_handler(const wchar_t *expression,
a8d4498
+     const wchar_t *function,
a8d4498
+     const wchar_t *file,
a8d4498
+     unsigned int line,
a8d4498
+     uintptr_t pReserved)
a8d4498
+ {
a8d4498
+ }
a8d4498
+ 
a8d4498
+ # define SET_INVALID_PARAM_HANDLER \
a8d4498
+ 	((void)_set_invalid_parameter_handler(bad_param_handler))
a8d4498
+ #else
a8d4498
+ # define SET_INVALID_PARAM_HANDLER
a8d4498
+ #endif
a8d4498
+ 
a8d4498
  #ifdef FEAT_GUI_W32
a8d4498
  
a8d4498
  /*
a8d4498
***************
a8d4498
*** 1627,1632 ****
a8d4498
--- 1656,1664 ----
a8d4498
      extern int _fmode;
a8d4498
  #endif
a8d4498
  
a8d4498
+     /* Silently handle invalid parameters to CRT functions */
a8d4498
+     SET_INVALID_PARAM_HANDLER;
a8d4498
+ 
a8d4498
      /* Let critical errors result in a failure, not in a dialog box.  Required
a8d4498
       * for the timestamp test to work on removed floppies. */
a8d4498
      SetErrorMode(SEM_FAILCRITICALERRORS);
a8d4498
***************
a8d4498
*** 2103,2108 ****
a8d4498
--- 2135,2143 ----
a8d4498
      extern int _fmode;
a8d4498
  #endif
a8d4498
  
a8d4498
+     /* Silently handle invalid parameters to CRT functions */
a8d4498
+     SET_INVALID_PARAM_HANDLER;
a8d4498
+ 
a8d4498
      /* Let critical errors result in a failure, not in a dialog box.  Required
a8d4498
       * for the timestamp test to work on removed floppies. */
a8d4498
      SetErrorMode(SEM_FAILCRITICALERRORS);
a8d4498
*** ../vim-7.3.008/src/version.c	2010-09-21 16:56:29.000000000 +0200
a8d4498
--- src/version.c	2010-09-21 17:27:36.000000000 +0200
a8d4498
***************
a8d4498
*** 716,717 ****
a8d4498
--- 716,719 ----
a8d4498
  {   /* Add new patch number below this line */
a8d4498
+ /**/
a8d4498
+     9,
a8d4498
  /**/
a8d4498
a8d4498
-- 
a8d4498
Wizards had always known that the act of observation changed the thing that
a8d4498
was observed, and sometimes forgot that it also changed the observer too.
a8d4498
			Terry Pratchett  -  Interesting times
a8d4498
a8d4498
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
a8d4498
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
a8d4498
\\\        download, build and distribute -- http://www.A-A-P.org        ///
a8d4498
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///