OSDN Git Service

Correct a static string buffer aliasing issue.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 12 Jul 2013 15:27:32 +0000 (16:27 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 12 Jul 2013 15:27:32 +0000 (16:27 +0100)
ChangeLog
src/setup.cpp

index 6f61aa4..9146036 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2013-07-12  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
+       Correct a static string buffer aliasing issue.
+
+       * src/setup.cpp (SetupTool::setup_dll): New inline method; it ensures
+       that the buffer within approot_path() refers to the setup helper DLL.
+       (SetupTool::InitialiseSetupHookAPI): Use it, when loading the DLL.
+       (SetupTool::SetupTool): Use it again, when subsequently calling...
+       (_wunlink): ...this; it is now the preferred API, replacing...
+       (DeleteFileW): ...this; do not blindly assume that...
+       (SetupTool::dll_name): ...this remains unchanged between references;
+       it is an alias for the static buffer within approot_path().
+
+2013-07-12  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
        Add a custom profile for use by the setup tool.
 
        * xml/setup.xml: New file.
index 9f6d1ab..4616be8 100644 (file)
@@ -190,6 +190,13 @@ class SetupTool
     static const wchar_t *gui_program;
     int RunInstalledProgram( const wchar_t * );
 
+    inline wchar_t *setup_dll( void )
+    { /* Helper function to ensure that the static "approot_path" buffer
+       * specifies a reference path name for mingw-get-setup-0.dll
+       */
+      return approot_path( L"libexec\\mingw-get\\mingw-get-setup-0.dll" );
+    }
+
     inline void CreateApplicationLauncher
       ( int, const wchar_t *, const char *, const char * );
 };
@@ -449,8 +456,7 @@ bool SetupTool::InitialiseSetupHookAPI( void )
   /* Having successfully loaded the main DLL, we perform a similar
    * check for the setup tool's bridging DLL...
    */
-  dll_name = approot_path( L"libexec\\mingw-get\\mingw-get-setup-0.dll" );
-  if( (hook_dll = LoadLibraryW( dll_name )) == NULL )
+  if( (hook_dll = LoadLibraryW( dll_name = setup_dll() )) == NULL )
   {
     /* ...once again, abandoning the installation, if this is not
      * available; in this case, since we've already successfully
@@ -1050,7 +1056,7 @@ base_dll( NULL ), hook_dll( NULL )
      * then we must now unload them; we also have no further use for
      * mingw-get-setup-0.dll, so we may delete it.
      */
-    if( hook_dll != NULL ){ FreeLibrary( hook_dll ); DeleteFileW( dll_name ); }
+    if( hook_dll != NULL ){ FreeLibrary( hook_dll ); _wunlink( setup_dll() ); }
     if( base_dll != NULL ){ FreeLibrary( base_dll ); }
 
     /* We're done with the COM subsystem; release it.