summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow
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 /fpdfsdk/pdfwindow
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 'fpdfsdk/pdfwindow')
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.cpp4
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.h3
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.cpp2
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.h3
-rw-r--r--fpdfsdk/pdfwindow/PWL_ListBox.cpp6
-rw-r--r--fpdfsdk/pdfwindow/PWL_ListBox.h3
6 files changed, 12 insertions, 9 deletions
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
index 9321e0f606..9f5ab97858 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
@@ -265,7 +265,7 @@ void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
return;
m_pEdit = pdfium::MakeUnique<CPWL_CBEdit>();
- m_pEdit->AttachFFLData(m_pFormFiller);
+ m_pEdit->AttachFFLData(m_pFormFiller.Get());
PWL_CREATEPARAM ecp = cp;
ecp.pParentWnd = this;
@@ -306,7 +306,7 @@ void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
return;
m_pList = pdfium::MakeUnique<CPWL_CBListBox>();
- m_pList->AttachFFLData(m_pFormFiller);
+ m_pList->AttachFFLData(m_pFormFiller.Get());
PWL_CREATEPARAM lcp = cp;
lcp.pParentWnd = this;
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h
index a687eb8e94..19d9ab2a04 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
#include "fpdfsdk/pdfwindow/PWL_ListBox.h"
#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
@@ -100,7 +101,7 @@ class CPWL_ComboBox : public CPWL_Wnd {
int32_t m_nPopupWhere;
int32_t m_nSelectItem;
IPWL_Filler_Notify* m_pFillerNotify;
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp
index 90572746da..4e37e9bde4 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp
@@ -398,7 +398,7 @@ void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
CFX_SystemHandler* pSysHandler = GetSystemHandler();
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
GetTextColor().ToFXColor(GetTransparency()), rcClip,
- CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
+ CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get());
}
bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.h b/fpdfsdk/pdfwindow/PWL_Edit.h
index 5e1a36610d..bd3799141a 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.h
+++ b/fpdfsdk/pdfwindow/PWL_Edit.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "fpdfsdk/fxedit/fx_edit.h"
#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
@@ -136,7 +137,7 @@ class CPWL_Edit : public CPWL_EditCtrl {
IPWL_Filler_Notify* m_pFillerNotify;
bool m_bFocus;
CFX_FloatRect m_rcOldWindow;
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_EDIT_H_
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
index 8448204a74..b682959426 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
@@ -172,14 +172,14 @@ void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice,
if (pSysHandler && pSysHandler->IsSelectionImplemented()) {
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
GetTextColor().ToFXColor(255), rcList, ptOffset,
- nullptr, pSysHandler, m_pFormFiller);
- pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem);
+ nullptr, pSysHandler, m_pFormFiller.Get());
+ pSysHandler->OutputSelectedRect(m_pFormFiller.Get(), rcItem);
} else {
CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem,
ArgbEncode(255, 0, 51, 113));
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
ArgbEncode(255, 255, 255, 255), rcList, ptOffset,
- nullptr, pSysHandler, m_pFormFiller);
+ nullptr, pSysHandler, m_pFormFiller.Get());
}
} else {
CFX_SystemHandler* pSysHandler = GetSystemHandler();
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.h b/fpdfsdk/pdfwindow/PWL_ListBox.h
index 9f8f464efb..0de9c91195 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "fpdfsdk/fxedit/fx_edit.h"
#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
@@ -111,7 +112,7 @@ class CPWL_ListBox : public CPWL_Wnd {
IPWL_Filler_Notify* m_pFillerNotify;
private:
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_