Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
12a134fd
Commit
12a134fd
authored
May 24, 2015
by
Jacek Caban
Committed by
Alexandre Julliard
May 25, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Fixed buffer overflow in GetShortPathNameW.
parent
47319a00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
path.c
dlls/kernel32/path.c
+20
-2
path.c
dlls/kernel32/tests/path.c
+18
-4
No files found.
dlls/kernel32/path.c
View file @
12a134fd
...
...
@@ -443,7 +443,7 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
WCHAR
*
tmpshortpath
;
LPCWSTR
p
;
DWORD
sp
=
0
,
lp
=
0
;
DWORD
tmplen
;
DWORD
tmplen
,
buf_len
;
WIN32_FIND_DATAW
wfd
;
HANDLE
goit
;
...
...
@@ -462,7 +462,8 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
/* code below only removes characters from string, never adds, so this is
* the largest buffer that tmpshortpath will need to have */
tmpshortpath
=
HeapAlloc
(
GetProcessHeap
(),
0
,
(
strlenW
(
longpath
)
+
1
)
*
sizeof
(
WCHAR
));
buf_len
=
strlenW
(
longpath
)
+
1
;
tmpshortpath
=
HeapAlloc
(
GetProcessHeap
(),
0
,
buf_len
*
sizeof
(
WCHAR
));
if
(
!
tmpshortpath
)
{
SetLastError
(
ERROR_OUTOFMEMORY
);
...
...
@@ -524,6 +525,23 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
goit
=
FindFirstFileW
(
tmpshortpath
,
&
wfd
);
if
(
goit
==
INVALID_HANDLE_VALUE
)
goto
notfound
;
FindClose
(
goit
);
/* In rare cases (like "a.abcd") short path may be longer than original path.
* Make sure we have enough space in temp buffer. */
if
(
wfd
.
cAlternateFileName
&&
tmplen
<
strlenW
(
wfd
.
cAlternateFileName
))
{
WCHAR
*
new_buf
;
buf_len
+=
strlenW
(
wfd
.
cAlternateFileName
)
-
tmplen
;
new_buf
=
HeapReAlloc
(
GetProcessHeap
(),
0
,
tmpshortpath
,
buf_len
*
sizeof
(
WCHAR
));
if
(
!
new_buf
)
{
HeapFree
(
GetProcessHeap
(),
0
,
tmpshortpath
);
SetLastError
(
ERROR_OUTOFMEMORY
);
return
0
;
}
tmpshortpath
=
new_buf
;
}
strcpyW
(
tmpshortpath
+
sp
,
wfd
.
cAlternateFileName
[
0
]
?
wfd
.
cAlternateFileName
:
wfd
.
cFileName
);
sp
+=
strlenW
(
tmpshortpath
+
sp
);
lp
+=
tmplen
;
...
...
dlls/kernel32/tests/path.c
View file @
12a134fd
...
...
@@ -1350,7 +1350,8 @@ static void test_GetShortPathNameW(void)
static
const
WCHAR
test_path
[]
=
{
'L'
,
'o'
,
'n'
,
'g'
,
'D'
,
'i'
,
'r'
,
'e'
,
'c'
,
't'
,
'o'
,
'r'
,
'y'
,
'N'
,
'a'
,
'm'
,
'e'
,
0
};
static
const
WCHAR
name
[]
=
{
't'
,
'e'
,
's'
,
't'
,
0
};
static
const
WCHAR
backSlash
[]
=
{
'\\'
,
0
};
WCHAR
path
[
MAX_PATH
],
tmppath
[
MAX_PATH
];
static
const
WCHAR
a_bcdeW
[]
=
{
'a'
,
'.'
,
'b'
,
'c'
,
'd'
,
'e'
,
0
};
WCHAR
path
[
MAX_PATH
],
tmppath
[
MAX_PATH
],
*
ptr
;
WCHAR
short_path
[
MAX_PATH
];
DWORD
length
;
HANDLE
file
;
...
...
@@ -1387,7 +1388,7 @@ static void test_GetShortPathNameW(void)
length
=
GetShortPathNameW
(
path
,
short_path
,
0
);
ok
(
length
,
"GetShortPathNameW returned 0.
\n
"
);
ret
=
GetShortPathNameW
(
path
,
short_path
,
length
);
ok
(
ret
,
"GetShortPathNameW returned 0.
\n
"
);
ok
(
ret
&&
ret
==
length
-
1
,
"GetShortPathNameW returned 0.
\n
"
);
lstrcatW
(
short_path
,
name
);
...
...
@@ -1399,11 +1400,24 @@ static void test_GetShortPathNameW(void)
file
=
CreateFileW
(
short_path
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
ok
(
file
!=
INVALID_HANDLE_VALUE
,
"File was not created.
\n
"
);
/* End test */
CloseHandle
(
file
);
ret
=
DeleteFileW
(
short_path
);
ok
(
ret
,
"Cannot delete file.
\n
"
);
ptr
=
path
+
lstrlenW
(
path
);
lstrcpyW
(
ptr
,
a_bcdeW
);
file
=
CreateFileW
(
path
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
ok
(
file
!=
INVALID_HANDLE_VALUE
,
"File was not created.
\n
"
);
CloseHandle
(
file
);
length
=
GetShortPathNameW
(
path
,
short_path
,
sizeof
(
short_path
)
/
sizeof
(
*
short_path
)
);
ok
(
length
,
"GetShortPathNameW failed: %u.
\n
"
,
GetLastError
()
);
ret
=
DeleteFileW
(
path
);
ok
(
ret
,
"Cannot delete file.
\n
"
);
*
ptr
=
0
;
/* End test */
ret
=
RemoveDirectoryW
(
path
);
ok
(
ret
,
"Cannot delete directory.
\n
"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment