Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(wwdownload): terminate registry strings and accept existing dirs

Olcay Seyganc30bdd9a4ed0
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/FTP.CPP b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/FTP.CPP
index 5fd8e05db..268307c6f 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/FTP.CPP
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/FTP.CPP
@@ -1833,7 +1833,9 @@ bool Prepare_Directories(const char *rootdir, const char *filename)
memset(tempstr,0,256);
strncpy(tempstr,filename,cptr-filename);
sprintf(newdir,"%s\\%s",rootdir, tempstr);
- if (!CreateDirectory(newdir, NULL))
+ // An existing directory is success, not failure - every download after the
+ // first into the same subdir used to bail out here.
+ if (!CreateDirectory(newdir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
return false;
//if ((_mkdir(newdir) == -1) && ((errno == ENOENT || errno==EACCES)))
//return(false);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/registry.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/registry.cpp
index 266470fcd..849b9c35a 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/registry.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDownload/registry.cpp
@@ -30,8 +30,11 @@
bool getStringFromRegistry(HKEY root, std::string path, std::string key, std::string& val)
{
HKEY handle;
- unsigned char buffer[256];
- unsigned long size = 256;
+ // Registry data is whatever is on disk: a zero-length value leaves buffer
+ // untouched, and REG_BINARY/REG_DWORD data carries no NUL at all. Both used
+ // to hand the caller a std::string built from uninitialized stack.
+ unsigned char buffer[256] = { 0 };
+ unsigned long size = sizeof(buffer);
unsigned long type;
int returnValue;
@@ -43,6 +46,7 @@ bool getStringFromRegistry(HKEY root, std::string path, std::string key, std::s
if (returnValue == ERROR_SUCCESS)
{
+ buffer[sizeof(buffer)-1] = '\0';
val = (char *)buffer;
return true;
}