1571b8a
To: vim-dev@vim.org
1571b8a
Subject: Patch 7.3.034
1571b8a
Fcc: outbox
1571b8a
From: Bram Moolenaar <Bram@moolenaar.net>
1571b8a
Mime-Version: 1.0
1571b8a
Content-Type: text/plain; charset=UTF-8
1571b8a
Content-Transfer-Encoding: 8bit
1571b8a
------------
1571b8a
1571b8a
Patch 7.3.034
1571b8a
Problem:    Win32: may be loading .dll from the wrong directory.
1571b8a
Solution:   Go to the Vim executable directory when opening a library.
1571b8a
Files:	    src/gui_w32.c, src/if_lua.c, src/if_mzsch.c, src/if_perl.xs,
1571b8a
	    src/if_python.c, src/if_python3.c, src/if_ruby.c, src/mbyte.c,
1571b8a
	    src/os_mswin.c, src/os_win32.c, src/proto/os_win32.pro
1571b8a
1571b8a
1571b8a
*** ../vim-7.3.033/src/gui_w32.c	2010-08-15 21:57:25.000000000 +0200
1571b8a
--- src/gui_w32.c	2010-10-22 21:49:27.000000000 +0200
1571b8a
***************
1571b8a
*** 1260,1266 ****
1571b8a
  
1571b8a
      /* try and load the user32.dll library and get the entry points for
1571b8a
       * multi-monitor-support. */
1571b8a
!     if ((user32_lib = LoadLibrary("User32.dll")) != NULL)
1571b8a
      {
1571b8a
  	pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib,
1571b8a
  							 "MonitorFromWindow");
1571b8a
--- 1260,1266 ----
1571b8a
  
1571b8a
      /* try and load the user32.dll library and get the entry points for
1571b8a
       * multi-monitor-support. */
1571b8a
!     if ((user32_lib = vimLoadLib("User32.dll")) != NULL)
1571b8a
      {
1571b8a
  	pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib,
1571b8a
  							 "MonitorFromWindow");
1571b8a
***************
1571b8a
*** 4188,4194 ****
1571b8a
      static void
1571b8a
  dyn_imm_load(void)
1571b8a
  {
1571b8a
!     hLibImm = LoadLibrary("imm32.dll");
1571b8a
      if (hLibImm == NULL)
1571b8a
  	return;
1571b8a
  
1571b8a
--- 4188,4194 ----
1571b8a
      static void
1571b8a
  dyn_imm_load(void)
1571b8a
  {
1571b8a
!     hLibImm = vimLoadLib("imm32.dll");
1571b8a
      if (hLibImm == NULL)
1571b8a
  	return;
1571b8a
  
1571b8a
*** ../vim-7.3.033/src/if_lua.c	2010-08-15 21:57:28.000000000 +0200
1571b8a
--- src/if_lua.c	2010-10-22 21:49:39.000000000 +0200
1571b8a
***************
1571b8a
*** 49,55 ****
1571b8a
  # define symbol_from_dll dlsym
1571b8a
  # define close_dll dlclose
1571b8a
  #else
1571b8a
! # define load_dll LoadLibrary
1571b8a
  # define symbol_from_dll GetProcAddress
1571b8a
  # define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
--- 49,55 ----
1571b8a
  # define symbol_from_dll dlsym
1571b8a
  # define close_dll dlclose
1571b8a
  #else
1571b8a
! # define load_dll vimLoadLib
1571b8a
  # define symbol_from_dll GetProcAddress
1571b8a
  # define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
*** ../vim-7.3.033/src/if_mzsch.c	2010-08-15 21:57:32.000000000 +0200
1571b8a
--- src/if_mzsch.c	2010-10-22 21:49:53.000000000 +0200
1571b8a
***************
1571b8a
*** 556,563 ****
1571b8a
  
1571b8a
      if (hMzGC && hMzSch)
1571b8a
  	return OK;
1571b8a
!     hMzSch = LoadLibrary(sch_dll);
1571b8a
!     hMzGC = LoadLibrary(gc_dll);
1571b8a
  
1571b8a
      if (!hMzSch)
1571b8a
      {
1571b8a
--- 556,563 ----
1571b8a
  
1571b8a
      if (hMzGC && hMzSch)
1571b8a
  	return OK;
1571b8a
!     hMzSch = vimLoadLib(sch_dll);
1571b8a
!     hMzGC = vimLoadLib(gc_dll);
1571b8a
  
1571b8a
      if (!hMzSch)
1571b8a
      {
1571b8a
*** ../vim-7.3.033/src/if_perl.xs	2010-08-15 21:57:30.000000000 +0200
1571b8a
--- src/if_perl.xs	2010-10-22 21:53:06.000000000 +0200
1571b8a
***************
1571b8a
*** 106,112 ****
1571b8a
  #define close_dll dlclose
1571b8a
  #else
1571b8a
  #define PERL_PROC FARPROC
1571b8a
! #define load_dll LoadLibrary
1571b8a
  #define symbol_from_dll GetProcAddress
1571b8a
  #define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
--- 106,112 ----
1571b8a
  #define close_dll dlclose
1571b8a
  #else
1571b8a
  #define PERL_PROC FARPROC
1571b8a
! #define load_dll vimLoadLib
1571b8a
  #define symbol_from_dll GetProcAddress
1571b8a
  #define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
*** ../vim-7.3.033/src/if_python.c	2010-08-15 21:57:28.000000000 +0200
1571b8a
--- src/if_python.c	2010-10-22 21:49:57.000000000 +0200
1571b8a
***************
1571b8a
*** 110,116 ****
1571b8a
  #  define close_dll dlclose
1571b8a
  #  define symbol_from_dll dlsym
1571b8a
  # else
1571b8a
! #  define load_dll LoadLibrary
1571b8a
  #  define close_dll FreeLibrary
1571b8a
  #  define symbol_from_dll GetProcAddress
1571b8a
  # endif
1571b8a
--- 110,116 ----
1571b8a
  #  define close_dll dlclose
1571b8a
  #  define symbol_from_dll dlsym
1571b8a
  # else
1571b8a
! #  define load_dll vimLoadLib
1571b8a
  #  define close_dll FreeLibrary
1571b8a
  #  define symbol_from_dll GetProcAddress
1571b8a
  # endif
1571b8a
*** ../vim-7.3.033/src/if_python3.c	2010-08-15 21:57:28.000000000 +0200
1571b8a
--- src/if_python3.c	2010-10-22 21:50:01.000000000 +0200
1571b8a
***************
1571b8a
*** 88,94 ****
1571b8a
  #  define close_dll dlclose
1571b8a
  #  define symbol_from_dll dlsym
1571b8a
  # else
1571b8a
! #  define load_dll LoadLibrary
1571b8a
  #  define close_dll FreeLibrary
1571b8a
  #  define symbol_from_dll GetProcAddress
1571b8a
  # endif
1571b8a
--- 88,94 ----
1571b8a
  #  define close_dll dlclose
1571b8a
  #  define symbol_from_dll dlsym
1571b8a
  # else
1571b8a
! #  define load_dll vimLoadLib
1571b8a
  #  define close_dll FreeLibrary
1571b8a
  #  define symbol_from_dll GetProcAddress
1571b8a
  # endif
1571b8a
*** ../vim-7.3.033/src/if_ruby.c	2010-09-29 13:02:48.000000000 +0200
1571b8a
--- src/if_ruby.c	2010-10-22 21:50:04.000000000 +0200
1571b8a
***************
1571b8a
*** 55,61 ****
1571b8a
  # define symbol_from_dll dlsym
1571b8a
  # define close_dll dlclose
1571b8a
  #else
1571b8a
! # define load_dll LoadLibrary
1571b8a
  # define symbol_from_dll GetProcAddress
1571b8a
  # define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
--- 55,61 ----
1571b8a
  # define symbol_from_dll dlsym
1571b8a
  # define close_dll dlclose
1571b8a
  #else
1571b8a
! # define load_dll vimLoadLib
1571b8a
  # define symbol_from_dll GetProcAddress
1571b8a
  # define close_dll FreeLibrary
1571b8a
  #endif
1571b8a
*** ../vim-7.3.033/src/mbyte.c	2010-09-18 13:36:41.000000000 +0200
1571b8a
--- src/mbyte.c	2010-10-22 21:50:09.000000000 +0200
1571b8a
***************
1571b8a
*** 4159,4169 ****
1571b8a
  {
1571b8a
      if (hIconvDLL != 0 && hMsvcrtDLL != 0)
1571b8a
  	return TRUE;
1571b8a
!     hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL);
1571b8a
      if (hIconvDLL == 0)		/* sometimes it's called libiconv.dll */
1571b8a
! 	hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL_ALT);
1571b8a
      if (hIconvDLL != 0)
1571b8a
! 	hMsvcrtDLL = LoadLibrary(DYNAMIC_MSVCRT_DLL);
1571b8a
      if (hIconvDLL == 0 || hMsvcrtDLL == 0)
1571b8a
      {
1571b8a
  	/* Only give the message when 'verbose' is set, otherwise it might be
1571b8a
--- 4159,4169 ----
1571b8a
  {
1571b8a
      if (hIconvDLL != 0 && hMsvcrtDLL != 0)
1571b8a
  	return TRUE;
1571b8a
!     hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL);
1571b8a
      if (hIconvDLL == 0)		/* sometimes it's called libiconv.dll */
1571b8a
! 	hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT);
1571b8a
      if (hIconvDLL != 0)
1571b8a
! 	hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL);
1571b8a
      if (hIconvDLL == 0 || hMsvcrtDLL == 0)
1571b8a
      {
1571b8a
  	/* Only give the message when 'verbose' is set, otherwise it might be
1571b8a
*** ../vim-7.3.033/src/os_mswin.c	2010-08-15 21:57:29.000000000 +0200
1571b8a
--- src/os_mswin.c	2010-10-22 22:03:26.000000000 +0200
1571b8a
***************
1571b8a
*** 817,823 ****
1571b8a
--- 817,827 ----
1571b8a
      BOOL fRunTimeLinkSuccess = FALSE;
1571b8a
  
1571b8a
      // Get a handle to the DLL module.
1571b8a
+ # ifdef WIN16
1571b8a
      hinstLib = LoadLibrary(libname);
1571b8a
+ # else
1571b8a
+     hinstLib = vimLoadLib(libname);
1571b8a
+ # endif
1571b8a
  
1571b8a
      // If the handle is valid, try to get the function address.
1571b8a
      if (hinstLib != NULL)
1571b8a
*** ../vim-7.3.033/src/os_win32.c	2010-10-13 20:37:37.000000000 +0200
1571b8a
--- src/os_win32.c	2010-10-23 13:16:55.000000000 +0200
1571b8a
***************
1571b8a
*** 206,247 ****
1571b8a
  static int suppress_winsize = 1;	/* don't fiddle with console */
1571b8a
  #endif
1571b8a
  
1571b8a
      static void
1571b8a
  get_exe_name(void)
1571b8a
  {
1571b8a
!     char	temp[256];
1571b8a
!     static int	did_set_PATH = FALSE;
1571b8a
  
1571b8a
      if (exe_name == NULL)
1571b8a
      {
1571b8a
  	/* store the name of the executable, may be used for $VIM */
1571b8a
! 	GetModuleFileName(NULL, temp, 255);
1571b8a
  	if (*temp != NUL)
1571b8a
  	    exe_name = FullName_save((char_u *)temp, FALSE);
1571b8a
      }
1571b8a
  
1571b8a
!     if (!did_set_PATH && exe_name != NULL)
1571b8a
      {
1571b8a
! 	char_u	    *p;
1571b8a
! 	char_u	    *newpath;
1571b8a
! 
1571b8a
! 	/* Append our starting directory to $PATH, so that when doing "!xxd"
1571b8a
! 	 * it's found in our starting directory.  Needed because SearchPath()
1571b8a
! 	 * also looks there. */
1571b8a
! 	p = mch_getenv("PATH");
1571b8a
! 	newpath = alloc((unsigned)(STRLEN(p) + STRLEN(exe_name) + 2));
1571b8a
! 	if (newpath != NULL)
1571b8a
! 	{
1571b8a
! 	    STRCPY(newpath, p);
1571b8a
! 	    STRCAT(newpath, ";");
1571b8a
! 	    vim_strncpy(newpath + STRLEN(newpath), exe_name,
1571b8a
! 					    gettail_sep(exe_name) - exe_name);
1571b8a
! 	    vim_setenv((char_u *)"PATH", newpath);
1571b8a
! 	    vim_free(newpath);
1571b8a
  	}
1571b8a
  
1571b8a
! 	did_set_PATH = TRUE;
1571b8a
      }
1571b8a
  }
1571b8a
  
1571b8a
  #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
1571b8a
--- 206,268 ----
1571b8a
  static int suppress_winsize = 1;	/* don't fiddle with console */
1571b8a
  #endif
1571b8a
  
1571b8a
+ static char_u *exe_path = NULL;
1571b8a
+ 
1571b8a
      static void
1571b8a
  get_exe_name(void)
1571b8a
  {
1571b8a
!     char	temp[MAXPATHL];
1571b8a
!     char_u	*p;
1571b8a
  
1571b8a
      if (exe_name == NULL)
1571b8a
      {
1571b8a
  	/* store the name of the executable, may be used for $VIM */
1571b8a
! 	GetModuleFileName(NULL, temp, MAXPATHL - 1);
1571b8a
  	if (*temp != NUL)
1571b8a
  	    exe_name = FullName_save((char_u *)temp, FALSE);
1571b8a
      }
1571b8a
  
1571b8a
!     if (exe_path == NULL && exe_name != NULL)
1571b8a
      {
1571b8a
! 	exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
1571b8a
! 	if (exe_path != NULL)
1571b8a
! 	{
1571b8a
! 	    /* Append our starting directory to $PATH, so that when doing
1571b8a
! 	     * "!xxd" it's found in our starting directory.  Needed because
1571b8a
! 	     * SearchPath() also looks there. */
1571b8a
! 	    p = mch_getenv("PATH");
1571b8a
! 	    if (STRLEN(p) + STRLEN(exe_path) + 2 < MAXPATHL);
1571b8a
! 	    {
1571b8a
! 		STRCPY(temp, p);
1571b8a
! 		STRCAT(temp, ";");
1571b8a
! 		STRCAT(temp, exe_path);
1571b8a
! 		vim_setenv((char_u *)"PATH", temp);
1571b8a
! 	    }
1571b8a
  	}
1571b8a
+     }
1571b8a
+ }
1571b8a
+ 
1571b8a
+ /*
1571b8a
+  * Load library "name".
1571b8a
+  */
1571b8a
+     HINSTANCE
1571b8a
+ vimLoadLib(char *name)
1571b8a
+ {
1571b8a
+     HINSTANCE dll = NULL;
1571b8a
+     char old_dir[MAXPATHL];
1571b8a
  
1571b8a
!     if (exe_path == NULL)
1571b8a
! 	get_exe_name();
1571b8a
!     if (exe_path != NULL && mch_dirname(old_dir, MAXPATHL) == OK)
1571b8a
!     {
1571b8a
! 	/* Change directory to where the executable is, both to make sure we
1571b8a
! 	 * find a .dll there and to avoid looking for a .dll in the current
1571b8a
! 	 * directory. */
1571b8a
! 	mch_chdir(exe_path);
1571b8a
! 	dll = LoadLibrary(name);
1571b8a
! 	mch_chdir(old_dir);
1571b8a
      }
1571b8a
+     return dll;
1571b8a
  }
1571b8a
  
1571b8a
  #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
1571b8a
***************
1571b8a
*** 254,260 ****
1571b8a
  static char *null_libintl_bindtextdomain(const char *, const char *);
1571b8a
  static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
1571b8a
  
1571b8a
! static HINSTANCE hLibintlDLL = 0;
1571b8a
  char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
1571b8a
  char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
1571b8a
  char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
1571b8a
--- 275,281 ----
1571b8a
  static char *null_libintl_bindtextdomain(const char *, const char *);
1571b8a
  static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
1571b8a
  
1571b8a
! static HINSTANCE hLibintlDLL = NULL;
1571b8a
  char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
1571b8a
  char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
1571b8a
  char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
1571b8a
***************
1571b8a
*** 282,307 ****
1571b8a
      if (hLibintlDLL)
1571b8a
  	return 1;
1571b8a
      /* Load gettext library (libintl.dll) */
1571b8a
!     hLibintlDLL = LoadLibrary(libname != NULL ? libname : GETTEXT_DLL);
1571b8a
      if (!hLibintlDLL)
1571b8a
      {
1571b8a
! 	char_u	    dirname[_MAX_PATH];
1571b8a
! 
1571b8a
! 	/* Try using the path from gvim.exe to find the .dll there. */
1571b8a
! 	get_exe_name();
1571b8a
! 	STRCPY(dirname, exe_name);
1571b8a
! 	STRCPY(gettail(dirname), GETTEXT_DLL);
1571b8a
! 	hLibintlDLL = LoadLibrary((char *)dirname);
1571b8a
! 	if (!hLibintlDLL)
1571b8a
  	{
1571b8a
! 	    if (p_verbose > 0)
1571b8a
! 	    {
1571b8a
! 		verbose_enter();
1571b8a
! 		EMSG2(_(e_loadlib), GETTEXT_DLL);
1571b8a
! 		verbose_leave();
1571b8a
! 	    }
1571b8a
! 	    return 0;
1571b8a
  	}
1571b8a
      }
1571b8a
      for (i = 0; libintl_entry[i].name != NULL
1571b8a
  					 && libintl_entry[i].ptr != NULL; ++i)
1571b8a
--- 303,318 ----
1571b8a
      if (hLibintlDLL)
1571b8a
  	return 1;
1571b8a
      /* Load gettext library (libintl.dll) */
1571b8a
!     hLibintlDLL = vimLoadLib(libname != NULL ? libname : GETTEXT_DLL);
1571b8a
      if (!hLibintlDLL)
1571b8a
      {
1571b8a
! 	if (p_verbose > 0)
1571b8a
  	{
1571b8a
! 	    verbose_enter();
1571b8a
! 	    EMSG2(_(e_loadlib), GETTEXT_DLL);
1571b8a
! 	    verbose_leave();
1571b8a
  	}
1571b8a
+ 	return 0;
1571b8a
      }
1571b8a
      for (i = 0; libintl_entry[i].name != NULL
1571b8a
  					 && libintl_entry[i].ptr != NULL; ++i)
1571b8a
***************
1571b8a
*** 430,436 ****
1571b8a
  	     * Seems like a lot of overhead to load/unload ADVAPI32.DLL each
1571b8a
  	     * time we verify security...
1571b8a
  	     */
1571b8a
! 	    advapi_lib = LoadLibrary("ADVAPI32.DLL");
1571b8a
  	    if (advapi_lib != NULL)
1571b8a
  	    {
1571b8a
  		pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib,
1571b8a
--- 441,447 ----
1571b8a
  	     * Seems like a lot of overhead to load/unload ADVAPI32.DLL each
1571b8a
  	     * time we verify security...
1571b8a
  	     */
1571b8a
! 	    advapi_lib = vimLoadLib("ADVAPI32.DLL");
1571b8a
  	    if (advapi_lib != NULL)
1571b8a
  	    {
1571b8a
  		pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib,
1571b8a
*** ../vim-7.3.033/src/proto/os_win32.pro	2010-08-15 21:57:28.000000000 +0200
1571b8a
--- src/proto/os_win32.pro	2010-10-22 22:05:35.000000000 +0200
1571b8a
***************
1571b8a
*** 1,4 ****
1571b8a
--- 1,5 ----
1571b8a
  /* os_win32.c */
1571b8a
+ HINSTANCE vimLoadLib __ARGS((char *name));
1571b8a
  int dyn_libintl_init __ARGS((char *libname));
1571b8a
  void dyn_libintl_end __ARGS((void));
1571b8a
  void PlatformId __ARGS((void));
1571b8a
*** ../vim-7.3.033/src/version.c	2010-10-22 22:13:47.000000000 +0200
1571b8a
--- src/version.c	2010-10-23 13:55:21.000000000 +0200
1571b8a
***************
1571b8a
*** 716,717 ****
1571b8a
--- 716,719 ----
1571b8a
  {   /* Add new patch number below this line */
1571b8a
+ /**/
1571b8a
+     34,
1571b8a
  /**/
1571b8a
1571b8a
-- 
1571b8a
This is the polymorph virus!  Follow these instructions carefully:
1571b8a
1. Send this message to everybody you know.
1571b8a
2. Format your harddisk.
1571b8a
Thank you for your cooperation in spreading the most powerful virus ever!
1571b8a
1571b8a
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
1571b8a
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1571b8a
\\\        download, build and distribute -- http://www.A-A-P.org        ///
1571b8a
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///