From 2f6ed155a5cd0938cd298bf30b9ca28e610843ba Mon Sep 17 00:00:00 2001 From: Jun Fang Date: Sat, 6 Feb 2016 09:51:38 +0800 Subject: Add a parameter checker in CXFA_ScriptContext::QueryNodeByFlag() BUG=pdfium:380 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1674453004 . --- xfa/src/fxfa/src/parser/xfa_script_imp.cpp | 31 ++++++++++++----------- xfa/src/fxfa/src/parser/xfa_script_nodehelper.cpp | 5 ++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/xfa/src/fxfa/src/parser/xfa_script_imp.cpp b/xfa/src/fxfa/src/parser/xfa_script_imp.cpp index 00b9b945fa..3c8e1c14a3 100644 --- a/xfa/src/fxfa/src/parser/xfa_script_imp.cpp +++ b/xfa/src/fxfa/src/parser/xfa_script_imp.cpp @@ -143,23 +143,24 @@ FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, FXJSE_HVALUE hValue, FX_DWORD dwFlag, FX_BOOL bSetting) { + if (!refNode) + return false; XFA_RESOLVENODE_RS resolveRs; - int32_t iRet = ResolveObjects(refNode, propname, resolveRs, dwFlag); - FX_BOOL bResult = FALSE; - if (iRet > 0) { - bResult = TRUE; - if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - FXJSE_HVALUE pValue = GetJSValueFromMap(resolveRs.nodes[0]); - FXJSE_Value_Set(hValue, pValue); - } else if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { - XFA_LPCSCRIPTATTRIBUTEINFO lpAttributeInfo = resolveRs.pScriptAttribute; - if (lpAttributeInfo) { - (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( - hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); - } + if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) + return false; + if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { + FXJSE_HVALUE pValue = GetJSValueFromMap(resolveRs.nodes[0]); + FXJSE_Value_Set(hValue, pValue); + return true; + } + if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { + XFA_LPCSCRIPTATTRIBUTEINFO lpAttributeInfo = resolveRs.pScriptAttribute; + if (lpAttributeInfo) { + (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( + hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); } } - return bResult; + return true; } void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, const CFX_ByteStringC& szPropName, @@ -479,7 +480,7 @@ FX_BOOL CXFA_ScriptContext::QueryVariableHValue( const CFX_ByteStringC& szPropName, FXJSE_HVALUE hValue, FX_BOOL bGetter) { - if (pScriptNode->GetClassID() != XFA_ELEMENT_Script) { + if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) { return FALSE; } CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); diff --git a/xfa/src/fxfa/src/parser/xfa_script_nodehelper.cpp b/xfa/src/fxfa/src/parser/xfa_script_nodehelper.cpp index 8fe9348b51..7ef7382f69 100644 --- a/xfa/src/fxfa/src/parser/xfa_script_nodehelper.cpp +++ b/xfa/src/fxfa/src/parser/xfa_script_nodehelper.cpp @@ -43,11 +43,12 @@ int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType, CXFA_NodeArray* pSiblings, FX_BOOL bIsClassName) { + if (!pNode) + return 0; CXFA_Node* parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); - if (parent == NULL) { + if (!parent) return 0; - } XFA_LPCPROPERTY pPropert = XFA_GetPropertyOfElement( parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN); if (!pPropert && eLogicType == XFA_LOGIC_Transparent) { -- cgit v1.2.3