Menu

#925 Math plugin compiled with mingw32 causes an access violation

2.0 Series
closed-fixed
Plugin (101)
5
2009-08-19
2009-08-11
f0rt
No

Environment
Operating System: Linux / Debian Sid [i386]
NSIS version: 2.44-4 (installed via Debian package, build log: https://buildd.debian.org/fetch.cgi?pkg=nsis&arch=i386&ver=2.44-4&stamp=1237526925&file=log&as=raw\)

How to reproduce the bug:
* Build Math plugin example on Debian Sid via the following command:
cd /tmp; makensis -NOCD /usr/share/doc/nsis/Examples/Math/math.nsi
* Copy the resulting math.exe file to a PC running Windows XP SP2 and execute math.exe by double clicking on its icon.
* The installer processes the Math::Script statements and prints out the results.
* Thereafter close the installer window and an access violation occurs.

Meticulously investigation revealed that the DllMain function of the Math plugin is not called so that
some values were not properly initialized.

The source files of the Math plugin actually require a C++ compiler to be built even so they
have the ".c" file extension. The mingw32 C++ compiler is not directly invoked but rather
via "i586-mingw32msvc-gcc -xc++" as you can see in the build log for the NSIS 2.44-4 Debian package:
i586-mingw32msvc-gcc -o build/release/Math/Source/Math.o -c -Wall -g -O2 -Os -Wall -fno-strict-aliasing -xc++ "-DNSISCALL= __attribute__((__stdcall__))" -Ibuild/release/api Contrib/Math/Source/Math.c

As a consequence name mangling (name decoration) occurs so that the DllMain function
is no longer recognized as an entry function by the linker. This ultimately caused
the previously described access violation because the DllMain function provided by the
Math plugin was not called and some values were not properly initialized.

Turning off the name mangling for the DllMain function fixes the issue:
--- nsis-2.45-src/Contrib/Math/Source/Math.c 2009-02-04 15:08:31.000000000 +0100
+++ nsis-2.45/Contrib/Math/Source/Math.c 2009-08-11 09:17:01.000000000 +0200
@@ -1552,7 +1552,7 @@
}
}

-BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID
lpReserved)
+extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG
ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance = hInst;
CleanAll(ul_reason_for_call == DLL_PROCESS_ATTACH);

Discussion

  • Paul Wise

    Paul Wise - 2009-08-19

    Appllied in SVN r5998. Please close the bug, I don't appear to have permission to do so.

     
  • f0rt

    f0rt - 2009-08-19
    • labels: --> Plugin
    • milestone: --> 2.0 Series
    • assigned_to: nobody --> pabs3
    • status: open --> closed-fixed
     
  • f0rt

    f0rt - 2009-08-19

    Thanks, fixed.

     
  • f0rt

    f0rt - 2009-08-19

    Thanks a lot for applying the patch.

     

Log in to post a comment.