[PATCH] riched20: Protect against pasting multi-line text in single-line control.

Huw Davies huw at codeweavers.com
Mon Nov 13 03:00:40 CST 2017


On Mon, Nov 13, 2017 at 12:23:17AM +0100, Rafał Harabień wrote:
> Signed-off-by: Rafał Harabień <rafalh1992 at o2.pl>
> ---
>  dlls/riched20/caret.c        |  4 ++++
>  dlls/riched20/tests/editor.c | 14 ++++++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
> index 26af743..8a99394 100644
> --- a/dlls/riched20/caret.c
> +++ b/dlls/riched20/caret.c
> @@ -551,6 +551,10 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
>        ME_DisplayItem *tp, *end_run, *run, *prev;
>        int eol_len = 0;
>  
> +      /* Check if new line is allowed for this control */
> +      if (!(editor->styleFlags & ES_MULTILINE))
> +        break;
> +
>        /* Find number of CR and LF in end of paragraph run */
>        if (*pos =='\r')
>        {

We have a check for ES_MULTILINE in the WM_SETTEXT handler.  While
here seems like a better place to add it, we'd need to test things
like EM_SETTEXTEX, EM_REPLACESEL and EM_STREAMIN to show that they all
exhibit this behaviour.  If they do then this is good and we can
remove the chehck in WM_SETTEXT.

> diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
> index a19ec85..d5fd8c0 100644
> --- a/dlls/riched20/tests/editor.c
> +++ b/dlls/riched20/tests/editor.c
> @@ -5509,10 +5513,20 @@ static void test_WM_PASTE(void)
>      /* Cut from read-only control */
>      SendMessageA(hwndRichEdit, EM_SETSEL, 0, -1);
>      SendMessageA(hwndRichEdit, WM_CUT, 0, 0);
> +    SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buffer);
>      result = strcmp(buffer,"cut\r\n");
>      ok(result == 0,
>          "test paste: strcmp = %i, actual = '%s'\n", result, buffer);
> +    OleFlushClipboard(); /* flush is needed because of broken OleClipboard implementation */

What is the issue with the ole clipboard?

> +    DestroyWindow(hwndRichEdit);

> +    /* Paste multi-line text into single-line control */

It would be better to paste in something that contained a 2nd line
to show that the 2nd line is dropped.

> +    hwndRichEdit = new_richedit_with_style(NULL, 0);
> +    SendMessageA(hwndRichEdit, WM_PASTE, 0, 0);
> +    SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buffer);
> +    result = strcmp(buffer,"cut");
> +    ok(result == 0,
> +        "test paste: strcmp = %i, actual = '%s'\n", result, buffer);
>      DestroyWindow(hwndRichEdit);
>  }



More information about the wine-devel mailing list