Bug with GetTextRange

41 views
Skip to first unread message

Paul K

unread,
Jun 4, 2016, 10:14:35 PM6/4/16
to scintilla-interest
Neil:

I think I found a small issue with GetTextRange in 3.6.6. When the provided buffer is not initialized with \0 and the requested range is outside of the document range, the returned len is reported based on provided cpMax and cpMin numbers, even though GetCharRange returns unmodified buffer, which is causing the caller to assume everything went well and get garbage in the buffer. The following patch fixes this for me:

--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -6000,6 +6000,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
                        if (lParam == 0)
                                return 0;
                        Sci_TextRange *tr = reinterpret_cast<Sci_TextRange *>(lParam);
+                       tr->lpstrText[0] = '\0';
                        int cpMax = static_cast<int>(tr->chrg.cpMax);
                        if (cpMax == -1)
                                cpMax = pdoc->Length();


Paul.

Neil Hodgson

unread,
Jun 5, 2016, 7:19:35 PM6/5/16
to scintilla-interest
Do not use invalid parameters to calls. Writing to the buffer in this case may cause problems with other users.
Reply all
Reply to author
Forward
0 new messages