Aric Stewart : version: Check for out of memory in VerInstallFileA/ W conversion (Coverity 635).
Alexandre Julliard
julliard at winehq.org
Mon Oct 6 09:35:17 CDT 2008
Module: wine
Branch: master
Commit: ea085768201dfb8338250b2740e01c7f4ce1f420
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ea085768201dfb8338250b2740e01c7f4ce1f420
Author: Aric Stewart <aric at codeweavers.com>
Date: Thu Oct 2 10:39:18 2008 -0500
version: Check for out of memory in VerInstallFileA/W conversion (Coverity 635).
---
dlls/version/install.c | 32 ++++++++++++++++++++++++--------
dlls/version/tests/install.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/dlls/version/install.c b/dlls/version/install.c
index d3170e3..2ecfeb9 100644
--- a/dlls/version/install.c
+++ b/dlls/version/install.c
@@ -535,7 +535,7 @@ DWORD WINAPI VerInstallFileW(
LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,PUINT tmpfilelen )
{
LPSTR wsrcf = NULL, wsrcd = NULL, wdestf = NULL, wdestd = NULL, wtmpf = NULL, wcurd = NULL;
- DWORD ret;
+ DWORD ret = 0;
UINT len;
if (srcfilename)
@@ -543,34 +543,50 @@ DWORD WINAPI VerInstallFileW(
len = WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, NULL, 0, NULL, NULL );
if ((wsrcf = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, wsrcf, len, NULL, NULL );
+ else
+ ret = VIF_OUTOFMEMORY;
}
- if (srcdir)
+ if (srcdir && !ret)
{
len = WideCharToMultiByte( CP_ACP, 0, srcdir, -1, NULL, 0, NULL, NULL );
if ((wsrcd = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, srcdir, -1, wsrcd, len, NULL, NULL );
+ else
+ ret = VIF_OUTOFMEMORY;
}
- if (destfilename)
+ if (destfilename && !ret)
{
len = WideCharToMultiByte( CP_ACP, 0, destfilename, -1, NULL, 0, NULL, NULL );
if ((wdestf = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, destfilename, -1, wdestf, len, NULL, NULL );
+ else
+ ret = VIF_OUTOFMEMORY;
}
- if (destdir)
+ if (destdir && !ret)
{
len = WideCharToMultiByte( CP_ACP, 0, destdir, -1, NULL, 0, NULL, NULL );
if ((wdestd = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, destdir, -1, wdestd, len, NULL, NULL );
+ else
+ ret = VIF_OUTOFMEMORY;
}
- if (curdir)
+ if (curdir && !ret)
{
len = WideCharToMultiByte( CP_ACP, 0, curdir, -1, NULL, 0, NULL, NULL );
if ((wcurd = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, curdir, -1, wcurd, len, NULL, NULL );
+ else
+ ret = VIF_OUTOFMEMORY;
}
- len = *tmpfilelen * sizeof(WCHAR);
- wtmpf = HeapAlloc( GetProcessHeap(), 0, len );
- ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,&len);
+ if (!ret)
+ {
+ len = *tmpfilelen * sizeof(WCHAR);
+ wtmpf = HeapAlloc( GetProcessHeap(), 0, len );
+ if (!wtmpf)
+ ret = VIF_OUTOFMEMORY;
+ }
+ if (!ret)
+ ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,&len);
if (!ret)
*tmpfilelen = MultiByteToWideChar( CP_ACP, 0, wtmpf, -1, tmpfile, *tmpfilelen );
else if (ret & VIF_BUFFTOOSMALL)
diff --git a/dlls/version/tests/install.c b/dlls/version/tests/install.c
index ada860c..ec40d3e 100644
--- a/dlls/version/tests/install.c
+++ b/dlls/version/tests/install.c
@@ -165,7 +165,48 @@ static void test_find_file(void)
}
}
+static void test_install_file(void)
+{
+ CHAR tmpname[MAX_PATH];
+ UINT size = MAX_PATH;
+ DWORD rc;
+ static const CHAR szSrcFileName[] = "nofile.txt";
+ static const CHAR szDestFileName[] = "nofile2.txt";
+ static const CHAR szSrcDir[] = "D:\\oes\\not\\exist";
+ static const CHAR szDestDir[] = "D:\\oes\\not\\exist\\either";
+ static const CHAR szCurDir[] = "C:\\";
+
+ /* testing Invalid Parameters */
+ memset(tmpname,0,sizeof(tmpname));
+ rc = VerInstallFileA(0x0, NULL, NULL, NULL, NULL, NULL, tmpname, &size);
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+ memset(tmpname,0,sizeof(tmpname));
+ size = MAX_PATH;
+ rc = VerInstallFileA(0x0, szSrcFileName, NULL, NULL, NULL, NULL, tmpname, &size);
+ memset(tmpname,0,sizeof(tmpname));
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+ size = MAX_PATH;
+ rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, NULL, NULL, NULL, tmpname, &size);
+ memset(tmpname,0,sizeof(tmpname));
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+ size = MAX_PATH;
+ rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, NULL, NULL, tmpname, &size);
+ memset(tmpname,0,sizeof(tmpname));
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+
+ /* Source file does not exist*/
+
+ size = MAX_PATH;
+ rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, szDestDir, NULL, tmpname, &size);
+ memset(tmpname,0,sizeof(tmpname));
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+ size = MAX_PATH;
+ rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, szDestDir, szCurDir, tmpname, &size);
+ ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
+}
+
START_TEST(install)
{
test_find_file();
+ test_install_file();
}
More information about the wine-cvs
mailing list