Changeset 30236 in webkit


Ignore:
Timestamp:
Feb 14, 2008 4:30:24 PM (16 years ago)
Author:
alp@webkit.org
Message:

2008-02-14 Alp Toker <alp@atoker.com>

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=17353
XMLTokenizer installs global libxml2 callbacks that can break client applications

Patch by Mark Rowe (with a few changes).

The xmlRegisterInputCallbacks/xmlRegisterOutputCallbacks done at
init are global so we need to make sure these callbacks only get used
by XMLTokenizer and never by libxml2 calls in user applications.

This patch modifies the match and open functions to only apply when we
are certain the caller is XMLTokenizer by checking globalDocLoader and
ensuring we're on the correct thread.

Some possible issues remain. See the bug report for details.

  • dom/XMLTokenizer.cpp: (WebCore::matchFunc): (WebCore::openFunc): (WebCore::createStringParser):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r30233 r30236  
     12008-02-14  Alp Toker  <alp@atoker.com>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=17353
     6        XMLTokenizer installs global libxml2 callbacks that can break client applications
     7
     8        Patch by Mark Rowe (with a few changes).
     9
     10        The xmlRegisterInputCallbacks/xmlRegisterOutputCallbacks done at
     11        init are global so we need to make sure these callbacks only get used
     12        by XMLTokenizer and never by libxml2 calls in user applications.
     13
     14        This patch modifies the match and open functions to only apply when we
     15        are certain the caller is XMLTokenizer by checking globalDocLoader and
     16        ensuring we're on the correct thread.
     17
     18        Some possible issues remain. See the bug report for details.
     19
     20        * dom/XMLTokenizer.cpp:
     21        (WebCore::matchFunc):
     22        (WebCore::openFunc):
     23        (WebCore::createStringParser):
     24
    1252008-02-14  Timothy Hatcher  <timothy@apple.com>
    226
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r30112 r30236  
    4848#include "ResourceRequest.h"
    4949#include "ResourceResponse.h"
     50#include "Threading.h"
    5051#ifndef USE_QXMLSTREAM
    5152#include <libxml/parser.h>
     
    341342
    342343static int globalDescriptor = 0;
     344static DocLoader* globalDocLoader = 0;
     345static ThreadIdentifier libxmlLoaderThread = 0;
    343346
    344347static int matchFunc(const char* uri)
    345348{
    346     return 1; // Match everything.
    347 }
    348 
    349 static DocLoader* globalDocLoader = 0;
     349    // Only match loads initiated due to uses of libxml2 from within XMLTokenizer to avoid
     350    // interfering with client applications that also use libxml2.  http://bugs.webkit.org/show_bug.cgi?id=17353
     351    return globalDocLoader && currentThread() == libxmlLoaderThread;
     352}
    350353
    351354class OffsetBuffer {
     
    378381static void* openFunc(const char* uri)
    379382{
    380     if (!globalDocLoader || !shouldAllowExternalLoad(uri))
     383    ASSERT(globalDocLoader);
     384    ASSERT(currentThread() == libxmlLoaderThread);
     385
     386    if (!shouldAllowExternalLoad(uri))
    381387        return &globalDescriptor;
    382388
     
    385391    Vector<char> data;
    386392   
    387     if (globalDocLoader->frame())
    388         globalDocLoader->frame()->loader()->loadResourceSynchronously(KURL(uri), error, response, data);
     393    DocLoader* docLoader = globalDocLoader;
     394    globalDocLoader = 0;
     395    // FIXME: We should restore the original global error handler as well.
     396
     397    if (docLoader->frame())
     398        docLoader->frame()->loader()->loadResourceSynchronously(KURL(uri), error, response, data);
     399
     400    globalDocLoader = docLoader;
    389401
    390402    return new OffsetBuffer(data);
     
    433445        xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc);
    434446        xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc);
     447        libxmlLoaderThread = currentThread();
    435448        didInit = true;
    436449    }
Note: See TracChangeset for help on using the changeset viewer.