~jconti/ubuntu/oneiric/webkit/fix_doc_path

« back to all changes in this revision

Viewing changes to WebCore/html/HTMLTokenizer.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2008-09-27 08:57:48 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080927085748-yhzld00w0rekp961
Tags: 1.0.1-4
WebCore/dom/Document.*, WebCore/loader/DocLoader.*: Avoid DoS via
crafted CSS import statements. Fixes: CVE-2008-3632. Closes: #499771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
              (C) 1997 Torben Weis (weis@kde.org)
4
4
              (C) 1998 Waldo Bastian (bastian@kde.org)
5
5
              (C) 2001 Dirk Mueller (mueller@kde.org)
6
 
    Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
 
6
    Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7
7
 
8
8
    This library is free software; you can redistribute it and/or
9
9
    modify it under the terms of the GNU Library General Public
17
17
 
18
18
    You should have received a copy of the GNU Library General Public License
19
19
    along with this library; see the file COPYING.LIB.  If not, write to
20
 
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
 
    Boston, MA 02111-1307, USA.
 
20
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
    Boston, MA 02110-1301, USA.
22
22
*/
23
23
 
24
24
#ifndef HTMLTokenizer_h
43
43
class FrameView;
44
44
class HTMLParser;
45
45
class Node;
 
46
class PreloadScanner;
46
47
 
47
48
/**
48
49
 * @internal
83
84
    OwnPtr<Vector<UChar> > m_sourceInfo;
84
85
};
85
86
 
 
87
enum DoctypeState {
 
88
    DoctypeBegin,
 
89
    DoctypeBeforeName,
 
90
    DoctypeName,
 
91
    DoctypeAfterName,
 
92
    DoctypeBeforePublicID,
 
93
    DoctypePublicID,
 
94
    DoctypeAfterPublicID,
 
95
    DoctypeBeforeSystemID,
 
96
    DoctypeSystemID,
 
97
    DoctypeAfterSystemID,
 
98
    DoctypeBogus
 
99
};
 
100
 
 
101
class DoctypeToken {
 
102
public:
 
103
    DoctypeToken() {}
 
104
    
 
105
    void reset()
 
106
    {
 
107
        m_name.clear();
 
108
        m_publicID.clear();
 
109
        m_systemID.clear();
 
110
        m_state = DoctypeBegin;
 
111
        m_source.clear();
 
112
    }
 
113
 
 
114
    DoctypeState state() { return m_state; }
 
115
    void setState(DoctypeState s) { m_state = s; }
 
116
 
 
117
    Vector<UChar> m_name;
 
118
    Vector<UChar> m_publicID;
 
119
    Vector<UChar> m_systemID;
 
120
    DoctypeState m_state;
 
121
    
 
122
    Vector<UChar> m_source;
 
123
};
 
124
 
86
125
//-----------------------------------------------------------------------------
87
126
 
88
127
class HTMLTokenizer : public Tokenizer, public CachedResourceClient {
100
139
    virtual bool processingData() const;
101
140
    virtual int executingScript() const { return m_executingScript; }
102
141
 
103
 
    virtual int lineNumber() const { return lineno; }
 
142
    virtual int lineNumber() const { return m_lineNumber; }
104
143
    virtual int columnNumber() const { return 1; }
105
144
 
106
 
    int* lineNumberPtr() { return &lineno; }
107
 
 
108
145
    bool processingContentWrittenByScript() const { return src.excludeLineNumbers(); }
 
146
    
 
147
    virtual void executeScriptsWaitingForStylesheets();
 
148
    
 
149
    virtual bool isHTMLTokenizer() const { return true; }
 
150
    HTMLParser* htmlParser() const { return parser; }
109
151
 
110
152
private:
111
153
    class State;
115
157
    void end();
116
158
 
117
159
    void reset();
 
160
 
118
161
    PassRefPtr<Node> processToken();
 
162
    void processDoctypeToken();
119
163
 
120
164
    State processListing(SegmentedString, State);
121
165
    State parseComment(SegmentedString&, State);
 
166
    State parseDoctype(SegmentedString&, State);
122
167
    State parseServer(SegmentedString&, State);
123
168
    State parseText(SegmentedString&, State);
124
169
    State parseSpecial(SegmentedString&, State);
126
171
    State parseEntity(SegmentedString&, UChar*& dest, State, unsigned& _cBufferPos, bool start, bool parsingTag);
127
172
    State parseProcessingInstruction(SegmentedString&, State);
128
173
    State scriptHandler(State);
129
 
    State scriptExecution(const DeprecatedString& script, State, DeprecatedString scriptURL, int baseLine = 0);
 
174
    State scriptExecution(const String& script, State, const String& scriptURL, int baseLine = 1);
130
175
    void setSrc(const SegmentedString&);
131
176
 
132
177
    // check if we have enough space in the buffer.
209
254
        void setInXmp(bool v) { setBit(InXmp, v); }
210
255
        bool inTitle() const { return testBit(InTitle); }
211
256
        void setInTitle(bool v) { setBit(InTitle, v); }
 
257
        bool inIFrame() const { return testBit(InIFrame); }
 
258
        void setInIFrame(bool v) { setBit(InIFrame, v); }
212
259
        bool inPlainText() const { return testBit(InPlainText); }
213
260
        void setInPlainText(bool v) { setBit(InPlainText, v); }
214
261
        bool inProcessingInstruction() const { return testBit(InProcessingInstruction); }
215
262
        void setInProcessingInstruction(bool v) { return setBit(InProcessingInstruction, v); }
216
263
        bool inComment() const { return testBit(InComment); }
217
264
        void setInComment(bool v) { setBit(InComment, v); }
 
265
        bool inDoctype() const { return testBit(InDoctype); }
 
266
        void setInDoctype(bool v) { setBit(InDoctype, v); }
218
267
        bool inTextArea() const { return testBit(InTextArea); }
219
268
        void setInTextArea(bool v) { setBit(InTextArea, v); }
220
269
        bool escaped() const { return testBit(Escaped); }
234
283
        bool forceSynchronous() const { return testBit(ForceSynchronous); }
235
284
        void setForceSynchronous(bool v) { setBit(ForceSynchronous, v); }
236
285
 
237
 
        bool inAnySpecial() const { return m_bits & (InScript | InStyle | InXmp | InTextArea | InTitle); }
 
286
        bool inAnySpecial() const { return m_bits & (InScript | InStyle | InXmp | InTextArea | InTitle | InIFrame); }
238
287
        bool hasTagState() const { return m_bits & TagMask; }
239
288
        bool hasEntityState() const { return m_bits & EntityMask; }
240
289
 
241
 
        bool needsSpecialWriteHandling() const { return m_bits & (InScript | InStyle | InXmp | InTextArea | InTitle | TagMask | EntityMask | InPlainText | InComment | InServer | InProcessingInstruction | StartTag); }
 
290
        bool needsSpecialWriteHandling() const { return m_bits & (InScript | InStyle | InXmp | InTextArea | InTitle | InIFrame | TagMask | EntityMask | InPlainText | InComment | InDoctype | InServer | InProcessingInstruction | StartTag); }
242
291
 
243
292
    private:
244
293
        static const int EntityShift = 4;
261
310
            DiscardLF = 1 << 20, // FIXME: should clarify difference between skip and discard
262
311
            AllowYield = 1 << 21,
263
312
            LoadingExtScript = 1 << 22,
264
 
            ForceSynchronous = 1 << 23
 
313
            ForceSynchronous = 1 << 23,
 
314
            InIFrame = 1 << 24,
 
315
            InDoctype = 1 << 25
265
316
        };
266
317
 
267
318
        void setBit(StateBits bit, bool value)
277
328
    };
278
329
 
279
330
    State m_state;
 
331
    
 
332
    DoctypeToken m_doctypeToken;
 
333
    int m_doctypeSearchCount;
 
334
    int m_doctypeSecondarySearchCount;
280
335
 
281
336
    bool brokenServer;
282
337
 
283
338
    // Name of an attribute that we just scanned.
284
339
    AtomicString attrName;
285
340
 
286
 
    // Used to store the code of a srcipting sequence
 
341
    // Used to store the code of a scripting sequence
287
342
    UChar* scriptCode;
288
343
    // Size of the script sequenze stored in @ref #scriptCode
289
344
    int scriptCodeSize;
294
349
 
295
350
    // Stores characters if we are scanning for a string like "</script>"
296
351
    UChar searchBuffer[10];
 
352
    
297
353
    // Counts where we are in the string we are scanning for
298
354
    int searchCount;
299
 
    // The string we are searching for
300
 
    const UChar* searchFor;
301
355
    // the stopper string
302
356
    const char* searchStopper;
303
357
    // the stopper len
304
358
    int searchStopperLen;
 
359
    
305
360
    // if no more data is coming, just parse what we have (including ext scripts that
306
361
    // may be still downloading) and finish
307
362
    bool noMoreData;
322
377
    RefPtr<Node> scriptNode;
323
378
 
324
379
    bool m_requestingScript;
 
380
    bool m_hasScriptsWaitingForStylesheets;
325
381
 
326
382
    // if we found one broken comment, there are most likely others as well
327
383
    // store a flag to get rid of the O(n^2) behaviour in such a case.
328
384
    bool brokenComments;
329
385
    // current line number
330
 
    int lineno;
 
386
    int m_lineNumber;
331
387
    // line number at which the current <script> started
332
388
    int scriptStartLineno;
333
389
    int tagStartLineno;
339
395
// So any fixed number might be too small, but rather than rewriting all usage of this buffer
340
396
// we'll just make it large enough to handle all imaginable cases.
341
397
#define CBUFLEN 1024
342
 
    char cBuffer[CBUFLEN + 2];
 
398
    UChar cBuffer[CBUFLEN + 2];
343
399
    unsigned int m_cBufferPos;
344
400
 
345
401
    SegmentedString src;
347
403
    HTMLParser* parser;
348
404
    bool inWrite;
349
405
    bool m_fragment;
 
406
 
 
407
    OwnPtr<PreloadScanner> m_preloadScanner;
350
408
};
351
409
 
352
410
void parseHTMLDocumentFragment(const String&, DocumentFragment*);