Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Side by Side Diff: Source/core/page/DOMSelection.cpp

Issue 15390003: Use-after-free in WebCore::Range::compareBoundaryPoints (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/DOMSelection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 437
438 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); 438 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange();
439 if (!selectedRange) 439 if (!selectedRange)
440 return; 440 return;
441 441
442 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); 442 selectedRange->deleteContents(ASSERT_NO_EXCEPTION);
443 443
444 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION); 444 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION);
445 } 445 }
446 446
447 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const 447 bool DOMSelection::containsNode(Node* n, bool allowPartial) const
448 { 448 {
449 if (!m_frame) 449 if (!m_frame)
450 return false; 450 return false;
451 451
452 // toNormalizedRange can trigger layout, which can remove the last
453 // reference to node |n|,
ojan 2013/05/20 02:30:48 The render tree doesn't hold refptrs to Nodes AFAI
454 RefPtr<Node> protect(n);
455
452 FrameSelection* selection = m_frame->selection(); 456 FrameSelection* selection = m_frame->selection();
453 457
454 if (!n || m_frame->document() != n->document() || selection->isNone()) 458 if (!n || m_frame->document() != n->document() || selection->isNone())
455 return false; 459 return false;
456 460
457 ContainerNode* parentNode = n->parentNode();
458 unsigned nodeIndex = n->nodeIndex(); 461 unsigned nodeIndex = n->nodeIndex();
459 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); 462 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange();
460 463
464 ContainerNode* parentNode = n->parentNode();
461 if (!parentNode) 465 if (!parentNode)
462 return false; 466 return false;
463 467
464 ExceptionCode ec = 0; 468 ExceptionCode ec = 0;
465 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), ec) >= 0 && !ec 469 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), ec) >= 0 && !ec
466 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), ec) <= 0 && !ec; 470 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), ec) <= 0 && !ec;
467 ASSERT(!ec); 471 ASSERT(!ec);
468 if (nodeFullySelected) 472 if (nodeFullySelected)
469 return true; 473 return true;
470 474
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 534
531 bool DOMSelection::isValidForPosition(Node* node) const 535 bool DOMSelection::isValidForPosition(Node* node) const
532 { 536 {
533 ASSERT(m_frame); 537 ASSERT(m_frame);
534 if (!node) 538 if (!node)
535 return true; 539 return true;
536 return node->document() == m_frame->document(); 540 return node->document() == m_frame->document();
537 } 541 }
538 542
539 } // namespace WebCore 543 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/DOMSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698