CVS: winex/files directory.c,1.25,1.26
[email protected] 1 Aug 2007 12:31:46 -0000
| Newsgroups | gmane.comp.emulators.winex.cvs |
|---|---|
| Message-ID | <[email protected]> |
Subject: winex/files directory.c,1.25,1.26Update of /var/lib/cvsd/cvsroot/winex/files
In directory agravaine:/tmp/cvs-serv29499/files
Modified Files:
directory.c
Log Message:
- fixed GetModuleFileNameA() to properly return a truncated filename error code. GetModuleFileNameW() just calls GetModuleFileNameA(), so its error codes should be updated as well.
- fixed all the calls to GetModuleFileNameA/W() to check for small buffer and bad module errors. Currently small buffer errors are just reported and are allowed to proceed with either an empty string or truncated string for the filename. In the case of an error retrieving the module filename (error == 0), the calling function reports the error and returns immediately.
Index: directory.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/files/directory.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- directory.c 31 Jul 2007 17:33:14 -0000 1.25
+++ directory.c 1 Aug 2007 12:31:44 -0000 1.26
@@ -803,17 +803,22 @@
/* FIXME: for now, GetModuleFileNameA can't return more */
/* than OFS_MAXPATHNAME. This may change with Win32. */
- char buffer[OFS_MAXPATHNAME];
- LPSTR p;
+ char buffer[OFS_MAXPATHNAME];
+ LPSTR p;
+ DWORD error;
if (!win32)
{
- if (!GetCurrentTask()) return FALSE;
- if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
- buffer[0]='\0';
+ if (!GetCurrentTask()) return FALSE;
+ if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
+ buffer[0]='\0';
} else {
- if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
- buffer[0]='\0';
+ error = GetModuleFileNameA( 0, buffer, sizeof(buffer) );
+ if (error == 0 || error == sizeof(buffer)){
+ ERR("could not retrieve the module file name (reason: '%s')\n", error == 0 ? "bad module" : "buffer too small");
+
+ buffer[0]='\0';
+ }
}
if (!(p = strrchr( buffer, '\\' ))) return FALSE;
if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
@@ -834,21 +839,31 @@
LPSTR lpFileName;
BOOL res = FALSE;
DWORD type, count;
+ DWORD error;
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths", &hkAppPaths) != ERROR_SUCCESS)
- return FALSE;
+ return FALSE;
- if (GetModuleFileNameA(0, lpAppName, sizeof(lpAppName)) == 0)
+
+ error = GetModuleFileNameA(0, lpAppName, sizeof(lpAppName));
+
+ if (error == sizeof(lpAppName)){
+ ERR("the buffer for GetModuleFileNameA() is too small!\n");
+
+ goto end;
+ }
+
+ else if (error == 0)
{
- WARN("huh, module not found ??\n");
- goto end;
+ WARN("huh, module not found ??\n");
+ goto end;
}
lpFileName = strrchr(lpAppName, '\\');
if (!lpFileName)
- goto end;
+ goto end;
else lpFileName++; /* skip '\\' */
if (RegOpenKeyA(hkAppPaths, lpFileName, &hkApp) != ERROR_SUCCESS)
- goto end;
+ goto end;
count = sizeof(lpAppPaths);
if (RegQueryValueExA(hkApp, "Path", 0, &type, (LPBYTE)lpAppPaths, &count) != ERROR_SUCCESS)
goto end2;