Changeset 57638 in webkit


Ignore:
Timestamp:
Apr 15, 2010 3:03:31 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-15 Bruno Schmidt <bruno.schmidt@gmail.com>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Null QObjects properties cause Segmentation Fault
https://bugs.webkit.org/show_bug.cgi?id=34730

QObjects exported to the QWebkit javascript with properties that are
a null "QObject*" cause Segmentation Fault.

If an QObject is added to the javascript context and it contains
properties of the type QObject* with NULL value, calling the property
causes Segmentation Fault.
So now the code below properly checks for null pointers:

  • bridge/qt/qt_instance.cpp: (JSC::Bindings::QtInstance::getClass): may return NULL (JSC::Bindings::QtInstance::getMethod): may return jsNull() (JSC::Bindings::QtInstance::stringValue): may return jsNull() (JSC::Bindings::QtInstance::booleanValue): may return false
  • bridge/qt/qt_runtime.cpp: (JSC::Bindings::convertValueToQVariant): (JSC::Bindings::convertQVariantToValue): May return jsNull on QObjectStar

2010-04-15 Bruno Schmidt <bruno.schmidt@gmail.com>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Null QObjects properties cause Segmentation Fault
https://bugs.webkit.org/show_bug.cgi?id=34730

QObjects exported to the QWebkit javascript with properties that are
a null "QObject*" cause Segmentation Fault.

If an QObject is added to the javascript context and it contains
properties of the type QObject* with NULL value, calling the property
causes Segmentation Fault.

Follow the tests for the corrections done over WebCore.

  • tests/qwebframe/tst_qwebframe.cpp: (MyQObject::MyQObject): init the field m_objectStar (MyQObject::objectStarProperty): read the Object* prop (MyQObject::setObjectStarProperty): write the Object* prop (tst_QWebFrame::getSetStaticProperty): new tests for the new prop
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57633 r57638  
     12010-04-15  Bruno Schmidt  <bruno.schmidt@gmail.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Null QObjects properties cause Segmentation Fault
     6        https://bugs.webkit.org/show_bug.cgi?id=34730
     7
     8        QObjects exported to the QWebkit javascript with properties that are
     9        a null "QObject*" cause Segmentation Fault.
     10
     11        If an QObject is added to the javascript context and it contains
     12        properties of the type QObject* with NULL value, calling the property
     13        causes Segmentation Fault.
     14        So now the code below properly checks for null pointers:
     15
     16        * bridge/qt/qt_instance.cpp:
     17        (JSC::Bindings::QtInstance::getClass): may return NULL
     18        (JSC::Bindings::QtInstance::getMethod): may return jsNull()
     19        (JSC::Bindings::QtInstance::stringValue): may return jsNull()
     20        (JSC::Bindings::QtInstance::booleanValue): may return false
     21        * bridge/qt/qt_runtime.cpp:
     22        (JSC::Bindings::convertValueToQVariant):
     23        (JSC::Bindings::convertQVariantToValue): May return jsNull on QObjectStar
     24
    1252010-04-14  Simon Fraser  <simon.fraser@apple.com>
    226
  • trunk/WebCore/bridge/qt/qt_instance.cpp

    r57334 r57638  
    172172Class* QtInstance::getClass() const
    173173{
     174    if (!m_object)
     175        return 0;
    174176    if (!m_class)
    175177        m_class = QtClass::classForObject(m_object);
     
    239241JSValue QtInstance::getMethod(ExecState* exec, const Identifier& propertyName)
    240242{
    241     MethodList methodList = getClass()->methodsNamed(propertyName, this);
     243    if (!getClass())
     244        return jsNull();
     245    MethodList methodList = m_class->methodsNamed(propertyName, this);
    242246    return new (exec) RuntimeMethod(exec, propertyName, methodList);
    243247}
     
    260264JSValue QtInstance::stringValue(ExecState* exec) const
    261265{
     266    QObject* obj = getObject();
     267    if (!obj)
     268        return jsNull();
     269
    262270    // Hmm.. see if there is a toString defined
    263271    QByteArray buf;
    264272    bool useDefault = true;
    265273    getClass();
    266     QObject* obj = getObject();
    267     if (m_class && obj) {
     274    if (m_class) {
    268275        // Cheat and don't use the full name resolution
    269276        int index = obj->metaObject()->indexOfMethod("toString()");
     
    310317{
    311318    // ECMA 9.2
    312     return jsBoolean(true);
     319    return jsBoolean(getObject());
    313320}
    314321
  • trunk/WebCore/bridge/qt/qt_runtime.cpp

    r55837 r57638  
    333333        }
    334334
    335         case QMetaType::QVariantMap: 
     335        case QMetaType::QVariantMap:
    336336            if (type == Object || type == Array || type == RTArray) {
    337337                // Enumerate the contents of the object
     
    872872    if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
    873873        QObject* obj = variant.value<QObject*>();
     874        if (!obj)
     875            return jsNull();
    874876        return QtInstance::getQtInstance(obj, root, QScriptEngine::QtOwnership)->createRuntimeObject(exec);
    875877    }
  • trunk/WebKit/qt/ChangeLog

    r57631 r57638  
     12010-04-15  Bruno Schmidt  <bruno.schmidt@gmail.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Null QObjects properties cause Segmentation Fault
     6        https://bugs.webkit.org/show_bug.cgi?id=34730
     7
     8        QObjects exported to the QWebkit javascript with properties that are
     9        a null "QObject*" cause Segmentation Fault.
     10
     11        If an QObject is added to the javascript context and it contains
     12        properties of the type QObject* with NULL value, calling the property
     13        causes Segmentation Fault.
     14
     15        Follow the tests for the corrections done over WebCore.
     16
     17        * tests/qwebframe/tst_qwebframe.cpp:
     18        (MyQObject::MyQObject): init the field m_objectStar
     19        (MyQObject::objectStarProperty): read the Object* prop
     20        (MyQObject::setObjectStarProperty): write the Object* prop
     21        (tst_QWebFrame::getSetStaticProperty): new tests for the new prop
     22
    1232010-04-14  Luiz Agostini  <luiz.agostini@openbossa.org>
    224
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r57388 r57638  
    6868    Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType)
    6969    Q_PROPERTY(QWebElement webElementProperty READ webElementProperty WRITE setWebElementProperty)
     70    Q_PROPERTY(QObject* objectStarProperty READ objectStarProperty WRITE setObjectStarProperty)
    7071    Q_ENUMS(Policy Strategy)
    7172    Q_FLAGS(Ability)
     
    105106            m_writeOnlyValue(789),
    106107            m_readOnlyValue(987),
     108            m_objectStar(0),
    107109            m_qtFunctionInvoked(-1) { }
    108110
     
    197199        m_customType = c;
    198200    }
     201
     202    QObject* objectStarProperty() const {
     203        return m_objectStar;
     204    }
     205
     206    void setObjectStarProperty(QObject* object) {
     207        m_objectStar = object;
     208    }
     209
    199210
    200211    int qtFunctionInvoked() const {
     
    483494    QWebElement m_webElement;
    484495    CustomType m_customType;
     496    QObject* m_objectStar;
    485497    int m_qtFunctionInvoked;
    486498    QVariantList m_actuals;
     
    879891                    "myObject.readOnlyProperty == 987"), sTrue);
    880892    QCOMPARE(m_myObject->readOnlyProperty(), 987);
     893
     894    // QObject* property
     895    m_myObject->setObjectStarProperty(0);
     896    QCOMPARE(m_myObject->objectStarProperty(), (QObject*)0);
     897    QCOMPARE(evalJS("myObject.objectStarProperty == null"), sTrue);
     898    QCOMPARE(evalJS("typeof myObject.objectStarProperty"), sObject);
     899    QCOMPARE(evalJS("Boolean(myObject.objectStarProperty)"), sFalse);
     900    QCOMPARE(evalJS("String(myObject.objectStarProperty) == 'null'"), sTrue);
     901    QCOMPARE(evalJS("myObject.objectStarProperty.objectStarProperty"),
     902        sUndefined);
     903    m_myObject->setObjectStarProperty(this);
     904    QCOMPARE(evalJS("myObject.objectStarProperty != null"), sTrue);
     905    QCOMPARE(evalJS("typeof myObject.objectStarProperty"), sObject);
     906    QCOMPARE(evalJS("Boolean(myObject.objectStarProperty)"), sTrue);
     907    QCOMPARE(evalJS("String(myObject.objectStarProperty) != 'null'"), sTrue);
    881908}
    882909
     
    28412868    QTest::qWaitForWindowShown(&view);
    28422869#else
    2843     QTest::qWait(2000); 
     2870    QTest::qWait(2000);
    28442871#endif
    28452872
Note: See TracChangeset for help on using the changeset viewer.