From da17d6cd9a4abc6ff41e18faa2757f98caf797db Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Thu, 3 Mar 2016 09:28:57 -0800 Subject: Don't allow empty expression in CXFA_FMParse::ParseParenExpression. BUG=pdfium:404 R=jun_fang@foxitsoftware.com, tsepez@chromium.org Review URL: https://codereview.chromium.org/1742903002 . --- xfa/src/fxfa/src/fm2js/xfa_error.cpp | 1 + xfa/src/fxfa/src/fm2js/xfa_error.h | 1 + xfa/src/fxfa/src/fm2js/xfa_fmparse.cpp | 36 ++++++++++++++++++---------------- 3 files changed, 21 insertions(+), 17 deletions(-) (limited to 'xfa') diff --git a/xfa/src/fxfa/src/fm2js/xfa_error.cpp b/xfa/src/fxfa/src/fm2js/xfa_error.cpp index fdeee363bb..03423b0673 100644 --- a/xfa/src/fxfa/src/fm2js/xfa_error.cpp +++ b/xfa/src/fxfa/src/fm2js/xfa_error.cpp @@ -11,6 +11,7 @@ static const FX_WCHAR* const gs_lpStrErrorMsgInfo[] = { L"invalidate char '%c'", L"expected identifier instead of '%s'", L"expected '%s' instead of '%s'", L"expected 'endif' instead of '%s'", L"unexpected expression '%s'", L"expected operator '%s' instead of '%s'", + L"expected non-empty expression", }; const FX_WCHAR* XFA_FM_ErrorMsg(XFA_FM_ERRMSG msg) { diff --git a/xfa/src/fxfa/src/fm2js/xfa_error.h b/xfa/src/fxfa/src/fm2js/xfa_error.h index 474b28b7c9..8907ad872f 100644 --- a/xfa/src/fxfa/src/fm2js/xfa_error.h +++ b/xfa/src/fxfa/src/fm2js/xfa_error.h @@ -19,6 +19,7 @@ enum XFA_FM_ERRMSG { FMERR_EXPECTED_IFEND, FMERR_UNEXPECTED_EXPRESSION, FMERR_EXPTECTED_OPERATOR, + FMERR_EXPECTED_NON_EMPTY_EXPRESSION, FMERR_MAXIMUM }; diff --git a/xfa/src/fxfa/src/fm2js/xfa_fmparse.cpp b/xfa/src/fxfa/src/fm2js/xfa_fmparse.cpp index 6841cdaca5..bd2c206f03 100644 --- a/xfa/src/fxfa/src/fm2js/xfa_fmparse.cpp +++ b/xfa/src/fxfa/src/fm2js/xfa_fmparse.cpp @@ -782,26 +782,28 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { } CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { - FX_DWORD line = m_pToken->m_uLinenum; Check(TOKlparen); - std::unique_ptr pExp1; - if (m_pToken->m_type != TOKrparen) { - pExp1.reset(ParseLogicalOrExpression()); - while (m_pToken->m_type == TOKassign) { - NextToken(); - std::unique_ptr pExp2( - ParseLogicalOrExpression()); - if (m_pErrorInfo->message.IsEmpty()) { - pExp1.reset(new CXFA_FMAssignExpression( - line, TOKassign, pExp1.release(), pExp2.release())); - } else { - pExp1.reset(); - } - } - Check(TOKrparen); - } else { + + if (m_pToken->m_type == TOKrparen) { + Error(m_pToken->m_uLinenum, FMERR_EXPECTED_NON_EMPTY_EXPRESSION); NextToken(); + return nullptr; } + + FX_DWORD line = m_pToken->m_uLinenum; + std::unique_ptr pExp1(ParseLogicalOrExpression()); + + while (m_pToken->m_type == TOKassign) { + NextToken(); + std::unique_ptr pExp2(ParseLogicalOrExpression()); + if (m_pErrorInfo->message.IsEmpty()) { + pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(), + pExp2.release())); + } else { + pExp1.reset(); + } + } + Check(TOKrparen); return pExp1.release(); } -- cgit v1.2.3