2008-10-23 Yael Aharon <yael.aharon@nokia.com>
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Oct 2008 13:42:35 +0000 (13:42 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Oct 2008 13:42:35 +0000 (13:42 +0000)
        Reviewed by Simon Hausmann.

        Invalid history entries could cause a crash in QT Webkit

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@37843 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebhistory.cpp
WebKit/qt/Api/qwebhistory.h
WebKit/qt/Api/qwebhistory_p.h
WebKit/qt/ChangeLog
WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

index 3f25a8a5b4a7393ed65031c3936f47eae8a58016..36ea3a56a15bfd15120e1ecfbc21e8855c5136b1 100644 (file)
@@ -85,7 +85,9 @@ QWebHistoryItem::~QWebHistoryItem()
 */
 QUrl QWebHistoryItem::originalUrl() const
 {
-    return QUrl(d->item->originalURL().string());
+    if (d->item)
+        return QUrl(d->item->originalURL().string());
+    return QUrl();
 }
 
 
@@ -96,7 +98,9 @@ QUrl QWebHistoryItem::originalUrl() const
 */
 QUrl QWebHistoryItem::url() const
 {
-    return QUrl(d->item->url().string());
+    if (d->item)
+        return QUrl(d->item->url().string());
+    return QUrl();
 }
 
 
@@ -107,7 +111,9 @@ QUrl QWebHistoryItem::url() const
 */
 QString QWebHistoryItem::title() const
 {
-    return d->item->title();
+    if (d->item)
+        return d->item->title();
+    return QString();
 }
 
 
@@ -119,7 +125,9 @@ QString QWebHistoryItem::title() const
 QDateTime QWebHistoryItem::lastVisited() const
 {
     //FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves
-    return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
+    if (d->item)
+        return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
+    return QDateTime();
 }
 
 
@@ -130,7 +138,9 @@ QDateTime QWebHistoryItem::lastVisited() const
 */
 QIcon QWebHistoryItem::icon() const
 {
-    return *d->item->icon()->nativeImageForCurrentFrame();
+    if (d->item)
+        return *d->item->icon()->nativeImageForCurrentFrame();
+    return QIcon();
 }
 
 /*!
@@ -141,6 +151,15 @@ QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
     d = priv;
 }
 
+/*!
+    \since 4.5
+    Returns whether this is a valid history item.
+*/
+bool QWebHistoryItem::isValid() const
+{
+    return d->item;
+}
+
 /*!
   \class QWebHistory
   \since 4.4
index 8d2c4096d6f4c71e92382a23e7e42fca46ebeb90..667a6dd14fced3877e9ea60f74c7984713c5b7b2 100644 (file)
@@ -46,6 +46,8 @@ public:
 
     QIcon icon() const;
 
+    bool isValid() const;
+
 private:
     QWebHistoryItem(QWebHistoryItemPrivate *priv);
     friend class QWebHistory;
index 790108bf3485d91c3b4bec00b951dd6ac4ed327d..32e69feea7f9122b86435b1e845441eeb913ba9f 100644 (file)
@@ -28,14 +28,15 @@ class QWebHistoryItemPrivate : public QSharedData
 public:
     QWebHistoryItemPrivate(WebCore::HistoryItem *i)
     {
-        i->ref();
+        if (i)
+            i->ref();
         item = i;
     }
     ~QWebHistoryItemPrivate()
     {
-        item->deref();
+        if (item)
+            item->deref();
     }
-    
     WebCore::HistoryItem *item;
 };
 
index 823127b72c2ce14928ee6eca888b053dd9615523..6ba482554267224ffc8953125fa1f51967e8f856 100644 (file)
@@ -1,3 +1,23 @@
+2008-10-23  Yael Aharon <yael.aharon@nokia.com>
+
+        Reviewed by Simon Hausmann.
+
+        Invalid history entries could cause a crash in QT Webkit
+
+        * Api/qwebhistory.cpp:
+        (QWebHistoryItem::originalUrl):
+        (QWebHistoryItem::url):
+        (QWebHistoryItem::title):
+        (QWebHistoryItem::lastVisited):
+        (QWebHistoryItem::icon):
+        (QWebHistoryItem::isValid):
+        * Api/qwebhistory.h:
+        * Api/qwebhistory_p.h:
+        (QWebHistoryItemPrivate::QWebHistoryItemPrivate):
+        (QWebHistoryItemPrivate::~QWebHistoryItemPrivate):
+        * tests/qwebpage/tst_qwebpage.cpp:
+        (tst_QWebPage::modified):
+
 2008-10-22  Yael Aharon <yael.aharon@nokia.com>
 
         Reviewed by Simon Hausmann.
index 5bd3568795499ac7845e1c884e677268cb83b0ce..09da25edc947f8fbbf482f07ac41434e1da0be0f 100644 (file)
@@ -294,6 +294,9 @@ void tst_QWebPage::modified()
     QVERIFY(m_page->history()->canGoBack());
     QVERIFY(!m_page->history()->canGoForward());
     QCOMPARE(m_page->history()->count(), 2);
+    QVERIFY(m_page->history()->backItem().isValid());
+    QVERIFY(!m_page->history()->forwardItem().isValid());
+
     m_page->history()->back();
     QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));