summaryrefslogtreecommitdiff
path: root/xfa/src/fxfa/src/fm2js/xfa_lexer.h
diff options
context:
space:
mode:
authorOliver Chang <ochang@chromium.org>2016-02-17 16:51:56 -0800
committerOliver Chang <ochang@chromium.org>2016-02-17 16:51:56 -0800
commit1e1d3b0f2bc6b6c185b37e0aa6b8663e901dc8bf (patch)
tree56197c6d5664950ce17eb42224523e13b6b2c103 /xfa/src/fxfa/src/fm2js/xfa_lexer.h
parent2398d8938277a2492b411f8f807bf1935918ccae (diff)
downloadpdfium-1e1d3b0f2bc6b6c185b37e0aa6b8663e901dc8bf.tar.xz
Fix some issues with CXFA_FMParse/CXFA_FMLexer infinite looping.chromium/2657chromium/2656chromium/2655
The parser did not expect an invalid token in some places, leading to an infinite loop. In the lexer, if an invalid string was found, the underlying pointer was never advanced. Also cleans some minor stuff along the way: - Remove nonsensical/useless destructors - Use unique_ptrs for owned members - Remove unused members - Other minor style changes BUG=587620 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1701363003 .
Diffstat (limited to 'xfa/src/fxfa/src/fm2js/xfa_lexer.h')
-rw-r--r--xfa/src/fxfa/src/fm2js/xfa_lexer.h25
1 files changed, 14 insertions, 11 deletions
diff --git a/xfa/src/fxfa/src/fm2js/xfa_lexer.h b/xfa/src/fxfa/src/fm2js/xfa_lexer.h
index 85b647e46c..14b927d6d9 100644
--- a/xfa/src/fxfa/src/fm2js/xfa_lexer.h
+++ b/xfa/src/fxfa/src/fm2js/xfa_lexer.h
@@ -6,6 +6,9 @@
#ifndef _XFA_FM_LEXER_H
#define _XFA_FM_LEXER_H
+
+#include <memory>
+
enum XFA_FM_TOKEN {
TOKand,
TOKlparen,
@@ -76,26 +79,28 @@ enum XFA_FM_TOKEN {
TOKnumber,
TOKreserver
};
+
struct XFA_FMKeyword {
XFA_FM_TOKEN m_type;
uint32_t m_uHash;
const FX_WCHAR* m_keword;
};
+
const FX_WCHAR* XFA_FM_KeywordToString(XFA_FM_TOKEN op);
+
class CXFA_FMToken {
public:
CXFA_FMToken();
- CXFA_FMToken(FX_DWORD uLineNum);
- ~CXFA_FMToken();
+ explicit CXFA_FMToken(FX_DWORD uLineNum);
+
CFX_WideStringC m_wstring;
XFA_FM_TOKEN m_type;
FX_DWORD m_uLinenum;
- CXFA_FMToken* m_pNext;
};
+
class CXFA_FMLexer {
public:
CXFA_FMLexer(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo);
- ~CXFA_FMLexer();
CXFA_FMToken* NextToken();
FX_DWORD Number(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd);
FX_DWORD String(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd);
@@ -106,10 +111,8 @@ class CXFA_FMLexer {
XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p);
void SetCurrentLine(FX_DWORD line) { m_uCurrentLine = line; }
void SetToken(CXFA_FMToken* pToken) {
- if (m_pToken) {
- delete m_pToken;
- }
- m_pToken = pToken;
+ if (m_pToken.get() != pToken)
+ m_pToken.reset(pToken);
}
const FX_WCHAR* SavePos() { return m_ptr; }
void RestorePos(const FX_WCHAR* pPos) { m_ptr = pPos; }
@@ -118,11 +121,11 @@ class CXFA_FMLexer {
protected:
CXFA_FMToken* Scan();
- const FX_WCHAR* m_pScript;
+
const FX_WCHAR* m_ptr;
- FX_STRSIZE m_uLength;
FX_DWORD m_uCurrentLine;
- CXFA_FMToken* m_pToken;
+ std::unique_ptr<CXFA_FMToken> m_pToken;
CXFA_FMErrorInfo* m_pErrorInfo;
};
+
#endif