Commit d4e9b2cd authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi: Fix the return value of MsiGetFileVersion for some corner cases.

parent cafbad3f
......@@ -3158,7 +3158,7 @@ static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
static const WCHAR szVersionResource[] = {'\\',0};
static const WCHAR szVersionFormat[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
static const WCHAR szLangFormat[] = {'%','d',0};
UINT ret = ERROR_SUCCESS;
UINT ret = ERROR_MORE_DATA;
DWORD len, error;
LPVOID version;
VS_FIXEDFILEINFO *ffi;
......@@ -3169,6 +3169,7 @@ static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
{
error = GetLastError();
if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
if (error == ERROR_RESOURCE_DATA_NOT_FOUND) return ERROR_FILE_INVALID;
return error;
}
if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
......@@ -3177,6 +3178,7 @@ static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
msi_free( version );
return GetLastError();
}
if (!verbuf && !verlen && !langbuf && !langlen) return ERROR_SUCCESS;
if (verlen)
{
if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
......@@ -3186,7 +3188,7 @@ static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
len = strlenW( tmp );
if (len >= *verlen) ret = ERROR_MORE_DATA;
if (*verlen > len) ret = ERROR_SUCCESS;
*verlen = len;
}
else
......@@ -3202,7 +3204,7 @@ static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
sprintfW( tmp, szLangFormat, *lang );
if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
len = strlenW( tmp );
if (len >= *langlen) ret = ERROR_MORE_DATA;
if (*langlen > len) ret = ERROR_SUCCESS;
*langlen = len;
}
else
......
......@@ -2829,6 +2829,9 @@ static void test_MsiGetFileVersion(void)
DWORD verchecksz, langchecksz;
/* NULL szFilePath */
r = MsiGetFileVersionA(NULL, NULL, NULL, NULL, NULL);
ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
versz = MAX_PATH;
langsz = MAX_PATH;
lstrcpyA(version, "version");
......@@ -2844,6 +2847,9 @@ static void test_MsiGetFileVersion(void)
ok(langsz == MAX_PATH, "Expected %d, got %d\n", MAX_PATH, langsz);
/* empty szFilePath */
r = MsiGetFileVersionA("", NULL, NULL, NULL, NULL);
ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", r);
versz = MAX_PATH;
langsz = MAX_PATH;
lstrcpyA(version, "version");
......@@ -2941,6 +2947,9 @@ static void test_MsiGetFileVersion(void)
create_file("ver.txt", "ver.txt", 20);
/* file exists, no version information */
r = MsiGetFileVersionA("ver.txt", NULL, NULL, NULL, NULL);
ok(r == ERROR_FILE_INVALID, "Expected ERROR_FILE_INVALID, got %d\n", r);
versz = MAX_PATH;
langsz = MAX_PATH;
lstrcpyA(version, "version");
......@@ -3042,6 +3051,34 @@ static void test_MsiGetFileVersion(void)
"Expected first character of %s, got %s\n", langcheck, lang);
ok(langsz >= langchecksz, "Expected %d >= %d\n", langsz, langchecksz);
/* pcchVersionBuf big enough, pcchLangBuf not big enough */
versz = MAX_PATH;
langsz = 0;
lstrcpyA(version, "version");
r = MsiGetFileVersionA(path, version, &versz, NULL, &langsz);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
ok(versz == verchecksz, "Expected %d, got %d\n", verchecksz, versz);
ok(!lstrcmpA(version, vercheck), "Expected %s, got %s\n", vercheck, version);
ok(langsz >= langchecksz && langsz < MAX_PATH, "Expected %d >= %d\n", langsz, langchecksz);
/* pcchVersionBuf not big enough, pcchLangBuf big enough */
versz = 5;
langsz = MAX_PATH;
lstrcpyA(lang, "lang");
r = MsiGetFileVersionA(path, NULL, &versz, lang, &langsz);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
ok(versz == verchecksz, "Expected %d, got %d\n", verchecksz, versz);
ok(langsz >= langchecksz && langsz < MAX_PATH, "Expected %d >= %d\n", langsz, langchecksz);
ok(lstrcmpA(lang, "lang"), "lang buffer not modified\n");
/* NULL pcchVersionBuf and pcchLangBuf */
r = MsiGetFileVersionA(path, version, NULL, lang, NULL);
ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
/* All NULL except szFilePath */
r = MsiGetFileVersionA(path, NULL, NULL, NULL, NULL);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
HeapFree(GetProcessHeap(), 0, vercheck);
HeapFree(GetProcessHeap(), 0, langcheck);
}
......
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