From cc205131b021ebded854958973f445ed121da1b8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 16 May 2017 14:01:47 -0700 Subject: 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 Reviewed-by: dsinclair Reviewed-by: Lei Zhang --- core/fpdfdoc/cpdf_filespec.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'core/fpdfdoc/cpdf_filespec.h') diff --git a/core/fpdfdoc/cpdf_filespec.h b/core/fpdfdoc/cpdf_filespec.h index ea002f0e22..fb71b57186 100644 --- a/core/fpdfdoc/cpdf_filespec.h +++ b/core/fpdfdoc/cpdf_filespec.h @@ -8,6 +8,7 @@ #define CORE_FPDFDOC_CPDF_FILESPEC_H_ #include "core/fxcrt/cfx_string_pool_template.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/cfx_weak_ptr.h" #include "core/fxcrt/fx_string.h" @@ -24,14 +25,14 @@ class CPDF_FileSpec { // Convert a pdf file name into platform dependent format. static CFX_WideString DecodeFileName(const CFX_WideStringC& filepath); - CPDF_Object* GetObj() const { return m_pObj; } + CPDF_Object* GetObj() const { return m_pObj.Get(); } bool GetFileName(CFX_WideString* wsFileName) const; // Set this file spec to refer to a file name (not a url). void SetFileName(const CFX_WideStringC& wsFileName); private: - CPDF_Object* const m_pObj; // not owned. + CFX_UnownedPtr const m_pObj; }; #endif // CORE_FPDFDOC_CPDF_FILESPEC_H_ -- cgit v1.2.3