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
6653d430
Commit
6653d430
authored
Nov 05, 2017
by
Rafał Harabień
Committed by
Alexandre Julliard
Nov 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user32: Protect single-line edit against pasting new line character.
Signed-off-by:
Rafał Harabień
<
rafalh1992@o2.pl
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
55412553
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
3 deletions
+99
-3
edit.c
dlls/user32/edit.c
+16
-2
edit.c
dlls/user32/tests/edit.c
+83
-1
No files found.
dlls/user32/edit.c
View file @
6653d430
...
...
@@ -3077,7 +3077,8 @@ static inline BOOL EDIT_IsInsideDialog(EDITSTATE *es)
static
void
EDIT_WM_Paste
(
EDITSTATE
*
es
)
{
HGLOBAL
hsrc
;
LPWSTR
src
;
LPWSTR
src
,
new_src
,
ptr
;
int
len
;
/* Protect read-only edit control from modification */
if
(
es
->
style
&
ES_READONLY
)
...
...
@@ -3086,7 +3087,20 @@ static void EDIT_WM_Paste(EDITSTATE *es)
OpenClipboard
(
es
->
hwndSelf
);
if
((
hsrc
=
GetClipboardData
(
CF_UNICODETEXT
)))
{
src
=
GlobalLock
(
hsrc
);
EDIT_EM_ReplaceSel
(
es
,
TRUE
,
src
,
TRUE
,
TRUE
);
/* Protect single-line edit against pasting new line character */
if
(
!
(
es
->
style
&
ES_MULTILINE
)
&&
((
ptr
=
strchrW
(
src
,
'\n'
))))
{
len
=
ptr
-
src
;
if
(
len
&&
src
[
len
-
1
]
==
'\r'
)
--
len
;
new_src
=
HeapAlloc
(
GetProcessHeap
(),
0
,
(
len
+
1
)
*
sizeof
(
WCHAR
));
if
(
new_src
!=
NULL
)
{
lstrcpynW
(
new_src
,
src
,
len
+
1
);
EDIT_EM_ReplaceSel
(
es
,
TRUE
,
new_src
,
TRUE
,
TRUE
);
HeapFree
(
GetProcessHeap
(),
0
,
new_src
);
}
}
else
EDIT_EM_ReplaceSel
(
es
,
TRUE
,
src
,
TRUE
,
TRUE
);
GlobalUnlock
(
hsrc
);
}
else
if
(
es
->
style
&
ES_PASSWORD
)
{
...
...
dlls/user32/tests/edit.c
View file @
6653d430
...
...
@@ -867,7 +867,7 @@ static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPAR
return
DefWindowProcA
(
hWnd
,
msg
,
wParam
,
lParam
);
}
/* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificati
s
ons sent in response
/* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notifications sent in response
* to these messages.
*/
static
void
test_edit_control_3
(
void
)
...
...
@@ -969,6 +969,19 @@ static void test_edit_control_3(void)
ok
(
lstrlenA
(
str
)
==
len
,
"text shouldn't have been truncated
\n
"
);
test_notify
(
1
,
0
,
1
);
SendMessageA
(
hWnd
,
WM_SETTEXT
,
0
,
(
LPARAM
)
""
);
zero_notify
();
SendMessageA
(
hWnd
,
EM_REPLACESEL
,
0
,
(
LPARAM
)
str2
);
len
=
SendMessageA
(
hWnd
,
WM_GETTEXTLENGTH
,
0
,
0
);
ok
(
lstrlenA
(
str2
)
==
len
,
"text shouldn't have been truncated
\n
"
);
test_notify
(
1
,
0
,
1
);
zero_notify
();
SendMessageA
(
hWnd
,
WM_SETTEXT
,
0
,
(
LPARAM
)
str2
);
len
=
SendMessageA
(
hWnd
,
WM_GETTEXTLENGTH
,
0
,
0
);
ok
(
lstrlenA
(
str2
)
==
len
,
"text shouldn't have been truncated
\n
"
);
test_notify
(
1
,
0
,
1
);
SendMessageA
(
hWnd
,
EM_SETLIMITTEXT
,
5
,
0
);
SendMessageA
(
hWnd
,
WM_SETTEXT
,
0
,
(
LPARAM
)
""
);
...
...
@@ -2831,6 +2844,74 @@ static void test_EM_GETHANDLE(void)
DestroyWindow
(
hEdit
);
}
static
void
test_paste
(
void
)
{
HWND
hEdit
,
hMultilineEdit
;
HANDLE
hmem
,
hmem_ret
;
char
*
buffer
;
int
r
,
len
;
static
const
char
*
str
=
"this is a simple text"
;
static
const
char
*
str2
=
"first line
\r\n
second line"
;
hEdit
=
create_editcontrol
(
ES_AUTOHSCROLL
|
ES_AUTOVSCROLL
,
0
);
hMultilineEdit
=
create_editcontrol
(
ES_AUTOHSCROLL
|
ES_AUTOVSCROLL
|
ES_MULTILINE
,
0
);
/* Prepare clipboard data with simple text */
hmem
=
GlobalAlloc
(
GMEM_MOVEABLE
,
255
);
ok
(
hmem
!=
NULL
,
"got %p (expected != NULL)
\n
"
,
hmem
);
buffer
=
GlobalLock
(
hmem
);
ok
(
buffer
!=
NULL
,
"got %p (expected != NULL)
\n
"
,
buffer
);
strcpy
(
buffer
,
str
);
GlobalUnlock
(
hmem
);
r
=
OpenClipboard
(
hEdit
);
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
r
=
EmptyClipboard
();
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
hmem_ret
=
SetClipboardData
(
CF_TEXT
,
hmem
);
ok
(
hmem_ret
==
hmem
,
"expected %p, got %p
\n
"
,
hmem
,
hmem_ret
);
r
=
CloseClipboard
();
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
/* Paste single line */
SendMessageA
(
hEdit
,
WM_SETTEXT
,
0
,
(
LPARAM
)
""
);
r
=
SendMessageA
(
hEdit
,
WM_PASTE
,
0
,
0
);
len
=
SendMessageA
(
hEdit
,
WM_GETTEXTLENGTH
,
0
,
0
);
ok
(
strlen
(
str
)
==
len
,
"expected %d, got %d
\n
"
,
strlen
(
str
),
len
);
/* Prepare clipboard data with multiline text */
hmem
=
GlobalAlloc
(
GMEM_MOVEABLE
,
255
);
ok
(
hmem
!=
NULL
,
"got %p (expected != NULL)
\n
"
,
hmem
);
buffer
=
GlobalLock
(
hmem
);
ok
(
buffer
!=
NULL
,
"got %p (expected != NULL)
\n
"
,
buffer
);
strcpy
(
buffer
,
str2
);
GlobalUnlock
(
hmem
);
r
=
OpenClipboard
(
hEdit
);
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
r
=
EmptyClipboard
();
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
hmem_ret
=
SetClipboardData
(
CF_TEXT
,
hmem
);
ok
(
hmem_ret
==
hmem
,
"expected %p, got %p
\n
"
,
hmem
,
hmem_ret
);
r
=
CloseClipboard
();
ok
(
r
==
TRUE
,
"expected %d, got %d
\n
"
,
TRUE
,
r
);
/* Paste multiline text in singleline edit - should be cut */
SendMessageA
(
hEdit
,
WM_SETTEXT
,
0
,
(
LPARAM
)
""
);
r
=
SendMessageA
(
hEdit
,
WM_PASTE
,
0
,
0
);
len
=
SendMessageA
(
hEdit
,
WM_GETTEXTLENGTH
,
0
,
0
);
ok
(
strlen
(
"first line"
)
==
len
,
"expected %d, got %d
\n
"
,
strlen
(
"first line"
),
len
);
/* Paste multiline text in multiline edit */
SendMessageA
(
hMultilineEdit
,
WM_SETTEXT
,
0
,
(
LPARAM
)
""
);
r
=
SendMessageA
(
hMultilineEdit
,
WM_PASTE
,
0
,
0
);
len
=
SendMessageA
(
hMultilineEdit
,
WM_GETTEXTLENGTH
,
0
,
0
);
ok
(
strlen
(
str2
)
==
len
,
"expected %d, got %d
\n
"
,
strlen
(
str2
),
len
);
/* Cleanup */
DestroyWindow
(
hEdit
);
DestroyWindow
(
hMultilineEdit
);
}
START_TEST
(
edit
)
{
...
...
@@ -2871,6 +2952,7 @@ START_TEST(edit)
win_skip
(
"EndMenu is not available
\n
"
);
test_EM_GETHANDLE
();
test_paste
();
UnregisterWindowClasses
();
}
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