[PATCH] check length in path canonicalize
Marcus Meissner
marcus at jet.franken.de
Sun Dec 3 04:11:37 CST 2006
Hi,
Fixes a buffer overflow caused by our testsuite.
Removes todo from test.
Made all static data in path.c static.
Ciao, Marcus
---
dlls/shlwapi/path.c | 9 ++++++++-
dlls/shlwapi/tests/path.c | 31 ++++++++++++++-----------------
2 files changed, 22 insertions(+), 18 deletions(-)
3e138116c372d2895a0a81e36c8924d834ec77ef
diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c
index f958f56..7673344 100644
--- a/dlls/shlwapi/path.c
+++ b/dlls/shlwapi/path.c
@@ -2341,7 +2341,14 @@ BOOL WINAPI PathCanonicalizeA(LPSTR lpsz
{
WCHAR szPath[MAX_PATH];
WCHAR szBuff[MAX_PATH];
- MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
+ INT ret;
+
+ ret = MultiByteToWideChar(CP_ACP,0,lpszPath,-1,NULL,0);
+ if (ret > MAX_PATH) {
+ FIXME("Too long path!\n");
+ return FALSE;
+ }
+ ret = MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,sizeof(szPath)/sizeof(WCHAR));
bRet = PathCanonicalizeW(szBuff, szPath);
WideCharToMultiByte(CP_ACP,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
}
diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c
index 9746fbc..db578fb 100644
--- a/dlls/shlwapi/tests/path.c
+++ b/dlls/shlwapi/tests/path.c
@@ -33,9 +33,9 @@ static HRESULT (WINAPI *pPathIsValidChar
static HRESULT (WINAPI *pPathIsValidCharW)(WCHAR,DWORD);
static LPWSTR (WINAPI *pPathCombineW)(LPWSTR, LPCWSTR, LPCWSTR);
-const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
-const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
-const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
+static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
+static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
+static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
typedef struct _TEST_URL_CANONICALIZE {
const char *url;
@@ -44,7 +44,7 @@ typedef struct _TEST_URL_CANONICALIZE {
const char *expecturl;
} TEST_URL_CANONICALIZE;
-const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
+const static TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
/*FIXME {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/"},*/
{"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests"},
{"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests"},
@@ -92,7 +92,7 @@ typedef struct _TEST_URL_ESCAPE {
const char *expecturl;
} TEST_URL_ESCAPE;
-const TEST_URL_ESCAPE TEST_ESCAPE[] = {
+const static TEST_URL_ESCAPE TEST_ESCAPE[] = {
{"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
{"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
{"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
@@ -181,7 +181,7 @@ typedef struct _TEST_URL_COMBINE {
const char *expecturl;
} TEST_URL_COMBINE;
-const TEST_URL_COMBINE TEST_COMBINE[] = {
+const static TEST_URL_COMBINE TEST_COMBINE[] = {
{"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
{"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
/*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
@@ -198,7 +198,7 @@ const TEST_URL_COMBINE TEST_COMBINE[] =
{"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"}
};
-struct {
+static struct {
const char *path;
const char *url;
DWORD ret;
@@ -218,7 +218,7 @@ struct {
#endif
};
-struct {
+static struct {
const char *url;
const char *path;
DWORD ret;
@@ -252,7 +252,7 @@ struct {
};
-struct {
+static struct {
char url[30];
const char *expect;
} TEST_URL_UNESCAPE[] = {
@@ -261,7 +261,7 @@ struct {
};
-struct {
+static struct {
const char *path;
BOOL expect;
} TEST_PATH_IS_URL[] = {
@@ -274,7 +274,7 @@ struct {
{"http:partial", TRUE}
};
-struct {
+static struct {
const char *url;
BOOL expectOpaque;
BOOL expectFile;
@@ -306,7 +306,7 @@ struct {
{ "file:partial", FALSE, TRUE }
};
-struct {
+static struct {
const char *path;
const char *result;
} TEST_PATH_UNQUOTE_SPACES[] = {
@@ -1464,11 +1464,8 @@ static void test_PathCanonicalizeA(void)
lstrcpy(dest, "test");
SetLastError(0xdeadbeef);
res = PathCanonicalizeA(dest, too_long);
- todo_wine
- {
- ok(!res, "Expected failure\n");
- ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
- }
+ ok(!res, "Expected failure\n");
+ ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
ok(lstrlen(too_long) == LONG_LEN - 1, "Expected length LONG_LEN - 1, got %i\n", lstrlen(too_long));
}
--
1.2.4
More information about the wine-patches
mailing list