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

Side by Side Diff: fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp

Issue 1566903002: XFA: Change the destruction order inside CPDFXFA_Document to avoid UAFs. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: nits Created 4 years, 11 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
« no previous file with comments | « fpdfsdk/include/fpdfxfa/fpdfxfa_doc.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 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fsdk_define.h" 7 #include "../../include/fsdk_define.h"
8 #include "../../include/fpdfxfa/fpdfxfa_doc.h" 8 #include "../../include/fpdfxfa/fpdfxfa_doc.h"
9 #include "../../include/fsdk_mgr.h" 9 #include "../../include/fsdk_mgr.h"
10 #include "../../include/fpdfxfa/fpdfxfa_app.h" 10 #include "../../include/fpdfxfa/fpdfxfa_app.h"
(...skipping 27 matching lines...) Expand all
38 : m_iDocType(DOCTYPE_PDF), 38 : m_iDocType(DOCTYPE_PDF),
39 m_pPDFDoc(pPDFDoc), 39 m_pPDFDoc(pPDFDoc),
40 m_pSDKDoc(nullptr), 40 m_pSDKDoc(nullptr),
41 m_pXFADoc(nullptr), 41 m_pXFADoc(nullptr),
42 m_pXFADocView(nullptr), 42 m_pXFADocView(nullptr),
43 m_pApp(pProvider), 43 m_pApp(pProvider),
44 m_pJSContext(nullptr) { 44 m_pJSContext(nullptr) {
45 } 45 }
46 46
47 CPDFXFA_Document::~CPDFXFA_Document() { 47 CPDFXFA_Document::~CPDFXFA_Document() {
48 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv())
49 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
50
51 delete m_pSDKDoc;
52
48 if (m_pPDFDoc) { 53 if (m_pPDFDoc) {
49 CPDF_Parser* pParser = (CPDF_Parser*)m_pPDFDoc->GetParser(); 54 CPDF_Parser* pParser = m_pPDFDoc->GetParser();
50 if (pParser == NULL) { 55 if (pParser)
56 delete pParser;
57 else
51 delete m_pPDFDoc; 58 delete m_pPDFDoc;
52 } else {
53 delete pParser;
54 }
55 m_pPDFDoc = NULL;
56 } 59 }
57 if (m_pXFADoc) { 60 if (m_pXFADoc) {
58 IXFA_App* pApp = m_pApp->GetXFAApp(); 61 IXFA_App* pApp = m_pApp->GetXFAApp();
59 if (pApp) { 62 if (pApp) {
60 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); 63 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();
61 if (pDocHandler) { 64 if (pDocHandler) {
62 CloseXFADoc(pDocHandler); 65 CloseXFADoc(pDocHandler);
63 } 66 }
64 } 67 }
65 } 68 }
66
67 if (m_pJSContext) {
68 if (m_pSDKDoc && m_pSDKDoc->GetEnv()) {
69 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
70 m_pJSContext = NULL;
71 }
72 }
73
74 if (m_pSDKDoc)
75 delete m_pSDKDoc;
76 m_pSDKDoc = NULL;
77 } 69 }
78 70
79 FX_BOOL CPDFXFA_Document::LoadXFADoc() { 71 FX_BOOL CPDFXFA_Document::LoadXFADoc() {
80 if (!m_pPDFDoc) 72 if (!m_pPDFDoc)
81 return FALSE; 73 return FALSE;
82 74
83 m_XFAPageList.RemoveAll(); 75 m_XFAPageList.RemoveAll();
84 76
85 IXFA_App* pApp = m_pApp->GetXFAApp(); 77 IXFA_App* pApp = m_pApp->GetXFAApp();
86 if (!pApp) 78 if (!pApp)
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 m_XFAPageList.SetAt(page->GetPageIndex(), NULL); 189 m_XFAPageList.SetAt(page->GetPageIndex(), NULL);
198 } 190 }
199 191
200 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( 192 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument(
201 CPDFDoc_Environment* pFormFillEnv) { 193 CPDFDoc_Environment* pFormFillEnv) {
202 if (!m_pSDKDoc && pFormFillEnv) 194 if (!m_pSDKDoc && pFormFillEnv)
203 m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv); 195 m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv);
204 return m_pSDKDoc; 196 return m_pSDKDoc;
205 } 197 }
206 198
207 void CPDFXFA_Document::ReleaseSDKDoc() {
208 if (m_pSDKDoc)
209 delete m_pSDKDoc;
210
211 m_pSDKDoc = NULL;
212 }
213
214 void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, 199 void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF,
215 CPDF_Rect& pdfRect) { 200 CPDF_Rect& pdfRect) {
216 pdfRect.left = fxRectF.left; 201 pdfRect.left = fxRectF.left;
217 pdfRect.top = fxRectF.bottom(); 202 pdfRect.top = fxRectF.bottom();
218 pdfRect.right = fxRectF.right(); 203 pdfRect.right = fxRectF.right();
219 pdfRect.bottom = fxRectF.top; 204 pdfRect.bottom = fxRectF.top;
220 } 205 }
221 206
222 //////////////////////////////////////////////////////////////////////////
223 void CPDFXFA_Document::SetChangeMark(IXFA_Doc* hDoc) { 207 void CPDFXFA_Document::SetChangeMark(IXFA_Doc* hDoc) {
224 if (hDoc == m_pXFADoc && m_pSDKDoc) { 208 if (hDoc == m_pXFADoc && m_pSDKDoc) {
225 m_pSDKDoc->SetChangeMark(); 209 m_pSDKDoc->SetChangeMark();
226 } 210 }
227 } 211 }
228 212
229 FX_BOOL CPDFXFA_Document::GetChangeMark(IXFA_Doc* hDoc) { 213 FX_BOOL CPDFXFA_Document::GetChangeMark(IXFA_Doc* hDoc) {
230 if (hDoc == m_pXFADoc && m_pSDKDoc) 214 if (hDoc == m_pXFADoc && m_pSDKDoc)
231 return m_pSDKDoc->GetChangeMark(); 215 return m_pSDKDoc->GetChangeMark();
232 return FALSE; 216 return FALSE;
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 } 1251 }
1268 1252
1269 return _GetHValueByName(szPropName, hValue, 1253 return _GetHValueByName(szPropName, hValue,
1270 m_pSDKDoc->GetEnv()->GetJSRuntime()); 1254 m_pSDKDoc->GetEnv()->GetJSRuntime());
1271 } 1255 }
1272 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, 1256 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name,
1273 FXJSE_HVALUE hValue, 1257 FXJSE_HVALUE hValue,
1274 IJS_Runtime* runTime) { 1258 IJS_Runtime* runTime) {
1275 return runTime->GetHValueByName(utf8Name, hValue); 1259 return runTime->GetHValueByName(utf8Name, hValue);
1276 } 1260 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698