Changeset 202757 in webkit


Ignore:
Timestamp:
Jul 1, 2016 1:59:08 PM (8 years ago)
Author:
Chris Dumez
Message:

[iOS] Possible null Range dereference under computeAutocorrectionContext()
https://bugs.webkit.org/show_bug.cgi?id=159328
<rdar://problem/26766720>

Reviewed by Benjamin Poulain.

Source/WebCore:

  • editing/Editor.cpp:

(WebCore::Editor::compositionRange):

  • editing/Editor.h:

Update to return a RefPtr instead of a PassRefPtr and use nullptr
instead of 0 in the implementation.

Source/WebKit2:

The code in computeAutocorrectionContext() was checking Editor::hasComposition()
before dereferencing Editor::compositionRange(). However, compositionRange()
can also return null in other cases (e.g. compositionStart == compositionEnd).

Drop the check for hasComposition() and do a null check on the value returned
by compositionRange() instead.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::computeAutocorrectionContext):

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r202753 r202757  
     12016-07-01  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Possible null Range dereference under computeAutocorrectionContext()
     4        https://bugs.webkit.org/show_bug.cgi?id=159328
     5        <rdar://problem/26766720>
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        * editing/Editor.cpp:
     10        (WebCore::Editor::compositionRange):
     11        * editing/Editor.h:
     12        Update to return a RefPtr instead of a PassRefPtr and use nullptr
     13        instead of 0 in the implementation.
     14
    1152016-07-01  Jon Davis  <jond@apple.com>
    216
  • trunk/Source/WebCore/editing/Editor.cpp

    r202295 r202757  
    28242824}
    28252825
    2826 PassRefPtr<Range> Editor::compositionRange() const
     2826RefPtr<Range> Editor::compositionRange() const
    28272827{
    28282828    if (!m_compositionNode)
    2829         return 0;
     2829        return nullptr;
    28302830    unsigned length = m_compositionNode->length();
    28312831    unsigned start = std::min(m_compositionStart, length);
    28322832    unsigned end = std::min(std::max(start, m_compositionEnd), length);
    28332833    if (start >= end)
    2834         return 0;
     2834        return nullptr;
    28352835    return Range::create(m_compositionNode->document(), m_compositionNode.get(), start, m_compositionNode.get(), end);
    28362836}
  • trunk/Source/WebCore/editing/Editor.h

    r200696 r202757  
    305305    WEBCORE_EXPORT void cancelComposition();
    306306    bool cancelCompositionIfSelectionIsInvalid();
    307     WEBCORE_EXPORT PassRefPtr<Range> compositionRange() const;
     307    WEBCORE_EXPORT RefPtr<Range> compositionRange() const;
    308308    WEBCORE_EXPORT bool getCompositionSelection(unsigned& selectionStart, unsigned& selectionEnd) const;
    309309
  • trunk/Source/WebKit2/ChangeLog

    r202754 r202757  
     12016-07-01  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Possible null Range dereference under computeAutocorrectionContext()
     4        https://bugs.webkit.org/show_bug.cgi?id=159328
     5        <rdar://problem/26766720>
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        The code in computeAutocorrectionContext() was checking Editor::hasComposition()
     10        before dereferencing Editor::compositionRange(). However, compositionRange()
     11        can also return null in other cases (e.g. compositionStart == compositionEnd).
     12
     13        Drop the check for hasComposition() and do a null check on the value returned
     14        by compositionRange() instead.
     15
     16        * WebProcess/WebPage/ios/WebPageIOS.mm:
     17        (WebKit::computeAutocorrectionContext):
     18
    1192016-07-01  Brent Fulgham  <bfulgham@apple.com>
    220
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r202754 r202757  
    21922192        selectedText = plainTextReplacingNoBreakSpace(frame.selection().selection().toNormalizedRange().get());
    21932193
    2194     if (frame.editor().hasComposition()) {
    2195         range = Range::create(*frame.document(), frame.editor().compositionRange()->startPosition(), startPosition);
     2194    if (auto compositionRange = frame.editor().compositionRange()) {
     2195        range = Range::create(*frame.document(), compositionRange->startPosition(), startPosition);
    21962196        String markedTextBefore;
    21972197        if (range)
    21982198            markedTextBefore = plainTextReplacingNoBreakSpace(range.get());
    2199         range = Range::create(*frame.document(), endPosition, frame.editor().compositionRange()->endPosition());
     2199        range = Range::create(*frame.document(), endPosition, compositionRange->endPosition());
    22002200        String markedTextAfter;
    22012201        if (range)
Note: See TracChangeset for help on using the changeset viewer.