GsNSIS / EnVar

EnVar plugin for NSIS
Other
8 stars 4 forks source link

[BUGFIX] Pass variable pointer to allow reallocation #4

Closed MiguelBarro closed 3 years ago

MiguelBarro commented 3 years ago

We are using the plugin to modify the PATH environment variable on installation. The environment is linked with two hives in the HKLM and HKCU roots in windows registry. The usual NSIS registry APIs like WriteRegXXX are constrained by the NSIS variable size (defaults to 1024). Because PATH is usually over these 1024 characters (up to 32760 in Windows 10) we resource to this plugin to workaround NSIS restrictions. Because the initial gptBuffer allocation are:

  if (!gptBuffer) gptBuffer = StrAlloc(16 * 1024);

working with a PATH variable under 16394 characters arises no issue, but if we try 20000 characters, for example, the installer hanged or crashed. We managed to zero the issue in the reallocation of the buffer. It turns out that the global variable keeps pointing to the old memory chunk and ignores the reallocation. We did our best to mend the issue and the changes work fine for us.

gilbertsoft commented 3 years ago

Thanks for you fix. Will have a look at your changes next week and do some tests.

gilbertsoft commented 3 years ago

Thanks again for your fix. I've now added tests to verify the behavior of the plugin. The final test uses up to 32,000 chars with the AddValue and DeleteValue, this is a little bit lower than the Windows limits but makes the testing easier. Could be optimized in a second step.

gilbertsoft commented 3 years ago

New beta release available now https://github.com/GsNSIS/EnVar/releases/tag/v0.3.1-beta