Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
b7bf2abd
Commit
b7bf2abd
authored
Mar 31, 2010
by
Andrew Nguyen
Committed by
Alexandre Julliard
Apr 01, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Improve parameter validation in OpenConsoleW.
parent
3db80a4b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
9 deletions
+95
-9
console.c
dlls/kernel32/console.c
+18
-9
console.c
dlls/kernel32/tests/console.c
+77
-0
No files found.
dlls/kernel32/console.c
View file @
b7bf2abd
...
@@ -274,23 +274,32 @@ BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
...
@@ -274,23 +274,32 @@ BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
*/
*/
HANDLE
WINAPI
OpenConsoleW
(
LPCWSTR
name
,
DWORD
access
,
BOOL
inherit
,
DWORD
creation
)
HANDLE
WINAPI
OpenConsoleW
(
LPCWSTR
name
,
DWORD
access
,
BOOL
inherit
,
DWORD
creation
)
{
{
HANDLE
output
;
HANDLE
output
=
INVALID_HANDLE_VALUE
;
HANDLE
ret
;
HANDLE
ret
;
if
(
strcmpiW
(
coninW
,
name
)
==
0
)
TRACE
(
"(%s, 0x%08x, %d, %u)
\n
"
,
debugstr_w
(
name
),
access
,
inherit
,
creation
);
output
=
(
HANDLE
)
FALSE
;
else
if
(
strcmpiW
(
conoutW
,
name
)
==
0
)
if
(
name
)
output
=
(
HANDLE
)
TRUE
;
else
{
{
SetLastError
(
ERROR_INVALID_NAME
);
if
(
strcmpiW
(
coninW
,
name
)
==
0
)
return
INVALID_HANDLE_VALUE
;
output
=
(
HANDLE
)
FALSE
;
else
if
(
strcmpiW
(
conoutW
,
name
)
==
0
)
output
=
(
HANDLE
)
TRUE
;
}
}
if
(
creation
!=
OPEN_EXISTING
)
if
(
output
==
INVALID_HANDLE_VALUE
)
{
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
INVALID_HANDLE_VALUE
;
return
INVALID_HANDLE_VALUE
;
}
}
else
if
(
creation
!=
OPEN_EXISTING
)
{
if
(
!
creation
||
creation
==
CREATE_NEW
||
creation
==
CREATE_ALWAYS
)
SetLastError
(
ERROR_SHARING_VIOLATION
);
else
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
INVALID_HANDLE_VALUE
;
}
SERVER_START_REQ
(
open_console
)
SERVER_START_REQ
(
open_console
)
{
{
...
...
dlls/kernel32/tests/console.c
View file @
b7bf2abd
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
static
BOOL
(
WINAPI
*
pGetConsoleInputExeNameA
)(
DWORD
,
LPSTR
);
static
BOOL
(
WINAPI
*
pGetConsoleInputExeNameA
)(
DWORD
,
LPSTR
);
static
DWORD
(
WINAPI
*
pGetConsoleProcessList
)(
LPDWORD
,
DWORD
);
static
DWORD
(
WINAPI
*
pGetConsoleProcessList
)(
LPDWORD
,
DWORD
);
static
HANDLE
(
WINAPI
*
pOpenConsoleW
)(
LPCWSTR
,
DWORD
,
BOOL
,
DWORD
);
static
BOOL
(
WINAPI
*
pSetConsoleInputExeNameA
)(
LPCSTR
);
static
BOOL
(
WINAPI
*
pSetConsoleInputExeNameA
)(
LPCSTR
);
/* DEFAULT_ATTRIB is used for all initial filling of the console.
/* DEFAULT_ATTRIB is used for all initial filling of the console.
...
@@ -65,6 +66,7 @@ static void init_function_pointers(void)
...
@@ -65,6 +66,7 @@ static void init_function_pointers(void)
hKernel32
=
GetModuleHandleA
(
"kernel32.dll"
);
hKernel32
=
GetModuleHandleA
(
"kernel32.dll"
);
KERNEL32_GET_PROC
(
GetConsoleInputExeNameA
);
KERNEL32_GET_PROC
(
GetConsoleInputExeNameA
);
KERNEL32_GET_PROC
(
GetConsoleProcessList
);
KERNEL32_GET_PROC
(
GetConsoleProcessList
);
KERNEL32_GET_PROC
(
OpenConsoleW
);
KERNEL32_GET_PROC
(
SetConsoleInputExeNameA
);
KERNEL32_GET_PROC
(
SetConsoleInputExeNameA
);
#undef KERNEL32_GET_PROC
#undef KERNEL32_GET_PROC
...
@@ -988,6 +990,80 @@ static void test_GetConsoleProcessList(void)
...
@@ -988,6 +990,80 @@ static void test_GetConsoleProcessList(void)
HeapFree
(
GetProcessHeap
(),
0
,
list
);
HeapFree
(
GetProcessHeap
(),
0
,
list
);
}
}
static
void
test_OpenConsoleW
(
void
)
{
static
const
WCHAR
coninW
[]
=
{
'C'
,
'O'
,
'N'
,
'I'
,
'N'
,
'$'
,
0
};
static
const
WCHAR
conoutW
[]
=
{
'C'
,
'O'
,
'N'
,
'O'
,
'U'
,
'T'
,
'$'
,
0
};
static
const
WCHAR
emptyW
[]
=
{
0
};
static
const
WCHAR
invalidW
[]
=
{
'I'
,
'N'
,
'V'
,
'A'
,
'L'
,
'I'
,
'D'
,
0
};
static
const
struct
{
LPCWSTR
name
;
DWORD
access
;
BOOL
inherit
;
DWORD
creation
;
DWORD
gle
;
}
invalid_table
[]
=
{
{
NULL
,
0
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
NULL
,
0xdeadbeef
,
0xdeadbeef
,
0xdeadbeef
,
ERROR_INVALID_PARAMETER
},
{
NULL
,
0
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
NULL
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
NULL
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
NULL
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_EXISTING
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
0
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
0xdeadbeef
,
0xdeadbeef
,
0xdeadbeef
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
0
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
emptyW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_EXISTING
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
0
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
0xdeadbeef
,
0xdeadbeef
,
0xdeadbeef
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
0
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
0
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
invalidW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_EXISTING
,
ERROR_INVALID_PARAMETER
},
{
coninW
,
0
,
FALSE
,
0
,
ERROR_SHARING_VIOLATION
},
{
coninW
,
0xdeadbeef
,
0xdeadbeef
,
0xdeadbeef
,
ERROR_INVALID_PARAMETER
},
{
coninW
,
0
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
coninW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
0
,
ERROR_SHARING_VIOLATION
},
{
coninW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
CREATE_NEW
,
ERROR_SHARING_VIOLATION
},
{
coninW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
CREATE_ALWAYS
,
ERROR_SHARING_VIOLATION
},
{
coninW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
coninW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
TRUNCATE_EXISTING
,
ERROR_INVALID_PARAMETER
},
{
conoutW
,
0
,
FALSE
,
0
,
ERROR_SHARING_VIOLATION
},
{
conoutW
,
0xdeadbeef
,
0xdeadbeef
,
0xdeadbeef
,
ERROR_INVALID_PARAMETER
},
{
conoutW
,
0
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
conoutW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
0
,
ERROR_SHARING_VIOLATION
},
{
conoutW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
CREATE_NEW
,
ERROR_SHARING_VIOLATION
},
{
conoutW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
CREATE_ALWAYS
,
ERROR_SHARING_VIOLATION
},
{
conoutW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
OPEN_ALWAYS
,
ERROR_INVALID_PARAMETER
},
{
conoutW
,
GENERIC_READ
|
GENERIC_WRITE
,
FALSE
,
TRUNCATE_EXISTING
,
ERROR_INVALID_PARAMETER
},
};
int
index
;
HANDLE
ret
;
if
(
!
pOpenConsoleW
)
{
win_skip
(
"OpenConsoleW is not available
\n
"
);
return
;
}
for
(
index
=
0
;
index
<
sizeof
(
invalid_table
)
/
sizeof
(
invalid_table
[
0
]);
index
++
)
{
SetLastError
(
0xdeadbeef
);
ret
=
pOpenConsoleW
(
invalid_table
[
index
].
name
,
invalid_table
[
index
].
access
,
invalid_table
[
index
].
inherit
,
invalid_table
[
index
].
creation
);
ok
(
ret
==
INVALID_HANDLE_VALUE
,
"Expected OpenConsoleW to return INVALID_HANDLE_VALUE for index %d, got %p
\n
"
,
index
,
ret
);
ok
(
GetLastError
()
==
invalid_table
[
index
].
gle
,
"Expected GetLastError() to return %u for index %d, got %u
\n
"
,
invalid_table
[
index
].
gle
,
index
,
GetLastError
());
}
}
START_TEST
(
console
)
START_TEST
(
console
)
{
{
HANDLE
hConIn
,
hConOut
;
HANDLE
hConIn
,
hConOut
;
...
@@ -1038,4 +1114,5 @@ START_TEST(console)
...
@@ -1038,4 +1114,5 @@ START_TEST(console)
test_GetSetConsoleInputExeName
();
test_GetSetConsoleInputExeName
();
test_GetConsoleProcessList
();
test_GetConsoleProcessList
();
test_OpenConsoleW
();
}
}
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