summaryrefslogtreecommitdiff
path: root/xfa/fxfa/cxfa_ffdocview.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-05-16 14:01:47 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-16 21:29:40 +0000
commitcc205131b021ebded854958973f445ed121da1b8 (patch)
tree18abcb19e5ec70dc8079cc7ad5192a5ff50aaf27 /xfa/fxfa/cxfa_ffdocview.cpp
parentd3a3cc24a034654b0825e4822446ddfc6a22c045 (diff)
downloadpdfium-cc205131b021ebded854958973f445ed121da1b8.tar.xz
Introduce CFX_UnownedPtr to detect lifetime inversion issues.
There are places where an object "child" has a raw pointer back to object "owner" with the understanding that owner will always outlive child. Violating this constraint can lead to use after free, but this requires finding two paths: one that frees the objects in the wrong order, and one that uses the object after the free. The purpose of this patch is to detect the constraint violation even when the second path is not hit. We create a template that is used in place of TYPE*. It's dtor, when a memory tool is present, goes out and probes the first byte of the object to which it points. Used in "child", this allows the memory tool to prove that the "owner" is still alive at the time the child is destroyed, and hence the constraint is never violated. Change-Id: I2a6d696d51dda4a79ee2f00a6752965e058a6417 Reviewed-on: https://pdfium-review.googlesource.com/5475 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fxfa/cxfa_ffdocview.cpp')
-rw-r--r--xfa/fxfa/cxfa_ffdocview.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 058116be72..c1a8a67336 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -61,9 +61,6 @@ CXFA_FFDocView::CXFA_FFDocView(CXFA_FFDoc* pDoc)
m_bInLayoutStatus(false),
m_pDoc(pDoc),
m_pXFADocLayout(nullptr),
- m_pFocusAcc(nullptr),
- m_pFocusWidget(nullptr),
- m_pOldFocusWidget(nullptr),
m_iStatus(XFA_DOCVIEW_LAYOUTSTATUS_None),
m_iLock(0) {}
@@ -143,14 +140,16 @@ void CXFA_FFDocView::StopLayout() {
nullptr);
}
m_CalculateAccs.clear();
- if (m_pFocusAcc && !m_pFocusWidget) {
- SetFocusWidgetAcc(m_pFocusAcc);
- }
+ if (m_pFocusAcc && !m_pFocusWidget)
+ SetFocusWidgetAcc(m_pFocusAcc.Get());
+
m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_End;
}
+
int32_t CXFA_FFDocView::GetLayoutStatus() {
return m_iStatus;
}
+
void CXFA_FFDocView::ShowNullTestMsg() {
int32_t iCount = pdfium::CollectionSize<int32_t>(m_arrNullTestMsg);
CXFA_FFApp* pApp = m_pDoc->GetApp();
@@ -316,8 +315,8 @@ CXFA_FFDocView::CreateWidgetAccIterator() {
return pdfium::MakeUnique<CXFA_WidgetAccIterator>(pFormRoot);
}
-CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() {
- return m_pFocusWidget;
+CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() const {
+ return m_pFocusWidget.Get();
}
void CXFA_FFDocView::KillFocus() {
@@ -329,12 +328,13 @@ void CXFA_FFDocView::KillFocus() {
m_pFocusWidget = nullptr;
m_pOldFocusWidget = nullptr;
}
+
bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
CXFA_FFWidget* pNewFocus = hWidget;
- if (m_pOldFocusWidget == pNewFocus) {
+ if (m_pOldFocusWidget == pNewFocus)
return false;
- }
- CXFA_FFWidget* pOldFocus = m_pOldFocusWidget;
+
+ CXFA_FFWidget* pOldFocus = m_pOldFocusWidget.Get();
m_pOldFocusWidget = pNewFocus;
if (pOldFocus) {
if (m_pFocusWidget != m_pOldFocusWidget &&
@@ -345,15 +345,15 @@ bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
if (!pOldFocus->IsLoaded()) {
pOldFocus->LoadWidget();
}
- pOldFocus->OnSetFocus(m_pFocusWidget);
+ pOldFocus->OnSetFocus(m_pFocusWidget.Get());
m_pFocusWidget = pOldFocus;
pOldFocus->OnKillFocus(pNewFocus);
}
}
- if (m_pFocusWidget == m_pOldFocusWidget) {
+ if (m_pFocusWidget == m_pOldFocusWidget)
return false;
- }
- pNewFocus = m_pOldFocusWidget;
+
+ pNewFocus = m_pOldFocusWidget.Get();
if (m_pListFocusWidget && pNewFocus == m_pListFocusWidget) {
m_pFocusAcc = nullptr;
m_pFocusWidget = nullptr;
@@ -362,29 +362,30 @@ bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
return false;
}
if (pNewFocus && (pNewFocus->GetStatus() & XFA_WidgetStatus_Visible)) {
- if (!pNewFocus->IsLoaded()) {
+ if (!pNewFocus->IsLoaded())
pNewFocus->LoadWidget();
- }
- pNewFocus->OnSetFocus(m_pFocusWidget);
+ pNewFocus->OnSetFocus(m_pFocusWidget.Get());
}
m_pFocusAcc = pNewFocus ? pNewFocus->GetDataAcc() : nullptr;
m_pFocusWidget = pNewFocus;
m_pOldFocusWidget = m_pFocusWidget;
return true;
}
+
CXFA_WidgetAcc* CXFA_FFDocView::GetFocusWidgetAcc() {
- return m_pFocusAcc;
+ return m_pFocusAcc.Get();
}
+
void CXFA_FFDocView::SetFocusWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) {
CXFA_FFWidget* pNewFocus =
pWidgetAcc ? pWidgetAcc->GetNextWidget(nullptr) : nullptr;
if (SetFocus(pNewFocus)) {
m_pFocusAcc = pWidgetAcc;
- if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End) {
- m_pDoc->GetDocEnvironment()->SetFocusWidget(m_pDoc, m_pFocusWidget);
- }
+ if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End)
+ m_pDoc->GetDocEnvironment()->SetFocusWidget(m_pDoc, m_pFocusWidget.Get());
}
}
+
void CXFA_FFDocView::DeleteLayoutItem(CXFA_FFWidget* pWidget) {
if (m_pFocusAcc == pWidget->GetDataAcc()) {
m_pFocusAcc = nullptr;
@@ -392,6 +393,7 @@ void CXFA_FFDocView::DeleteLayoutItem(CXFA_FFWidget* pWidget) {
m_pOldFocusWidget = nullptr;
}
}
+
static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView,
CXFA_WidgetAcc* pWidgetAcc,
CXFA_EventParam* pParam) {