CVS: winex/loader loadorder.c, 1.5, 1.6 module.c, 1.31, 1.32
[email protected] 1 Aug 2007 12:32:22 -0000
| Newsgroups | gmane.comp.emulators.winex.cvs |
|---|---|
| Message-ID | <[email protected]> |
Subject: winex/loader loadorder.c,1.5,1.6 module.c,1.31,1.32Update of /var/lib/cvsd/cvsroot/winex/loader
In directory agravaine:/tmp/cvs-serv29737/loader
Modified Files:
loadorder.c module.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: loadorder.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/loader/loadorder.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- loadorder.c 9 Jan 2006 18:29:59 -0000 1.5
+++ loadorder.c 1 Aug 2007 12:32:19 -0000 1.6
@@ -396,11 +396,12 @@
HKEY hkey, appkey;
DWORD count, type, res;
char buffer[MAX_PATH+16], *appname, *p;
+ DWORD error;
if (!GetModuleFileName16( GetCurrentTask(), buffer, MAX_PATH ) &&
- !GetModuleFileNameA( 0, buffer, MAX_PATH ))
+ ((error = GetModuleFileNameA( 0, buffer, MAX_PATH )) == 0 || error == MAX_PATH))
{
- WARN( "could not get module file name loading %s\n", module );
+ WARN( "could not get module file name loading %s (reason: '%s')\n", module, error == 0 ? "bad module" : "buffer too small");
return FALSE;
}
appname = buffer;
Index: module.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/loader/module.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- module.c 31 Jul 2007 19:30:20 -0000 1.31
+++ module.c 1 Aug 2007 12:32:19 -0000 1.32
@@ -1335,17 +1335,42 @@
LPSTR lpFileName, /* [out] filenamebuffer */
DWORD size ) /* [in] size of filenamebuffer */
{
- WINE_MODREF *wm;
+ WINE_MODREF * wm;
+ DWORD result = 0;
+ size_t len = 0;
+
take_loader_lock();
lpFileName[0] = 0;
- if ((wm = MODULE32_LookupHMODULE( hModule )))
+
+ /* retrieved the module filename => copy it to the destination buffer */
+ if ((wm = MODULE32_LookupHMODULE( hModule ))){
lstrcpynA( lpFileName, wm->filename, size );
+ len = strlen(wm->filename);
+ }
+
+ /* couldn't retrieve module name => fail */
+ else{
+ release_loader_lock();
+
+ return 0;
+ }
+
release_loader_lock();
+
+
+ /* buffer is too small to hold the string => fail (return buffer's size) */
+ if (len >= size)
+ result = size;
+
+ /* buffer is big enough to hold the string => succeed (return number of characters copied) */
+ else
+ result = len;
+
TRACE("%s\n", lpFileName );
- return strlen(lpFileName);
+ return result;
}