Commit ea085768 authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

version: Check for out of memory in VerInstallFileA/W conversion (Coverity 635).

parent 32af90d5
......@@ -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)
......
......@@ -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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment