Sanitize topic message 40/head
authorFlorent Castelli <florent.castelli@gmail.com>
Wed, 16 Oct 2013 21:15:23 +0000 (23:15 +0200)
committerFlorent Castelli <florent.castelli@gmail.com>
Wed, 16 Oct 2013 21:15:23 +0000 (23:15 +0200)
The code handling the topic message isn't expecting any new lines
since it is usually not possible to have any from the IRC specs.
But we can have some Unicode new lines instead!
Qt is happily converting them to simple new lines which then crashes
the client with a stack overflow.

src/qtui/topicwidget.cpp
src/qtui/topicwidget.h

index 827452c..13987e6 100644 (file)
@@ -156,12 +156,12 @@ void TopicWidget::setTopic(const QModelIndex &index)
         }
     }
 
-    _topic = newtopic;
+    _topic = sanitizeTopic(newtopic);
     _readonly = readonly;
 
     ui.topicEditButton->setVisible(!_readonly);
-    ui.topicLabel->setText(newtopic);
-    ui.topicLineEdit->setPlainText(newtopic);
+    ui.topicLabel->setText(_topic);
+    ui.topicLineEdit->setPlainText(_topic);
     switchPlain();
 }
 
@@ -264,3 +264,16 @@ bool TopicWidget::eventFilter(QObject *obj, QEvent *event)
 
     return false;
 }
+
+QString TopicWidget::sanitizeTopic(const QString& topic)
+{
+    // Normally, you don't have new lines in topic messages
+    // But the use of "plain text" functionnality from Qt replaces
+    // some unicode characters with a new line, which then triggers
+    // a stack overflow later
+    QString result(topic);
+    result.replace(QChar::ParagraphSeparator, " ");
+    result.replace(QChar::LineSeparator, " ");
+
+    return result;
+}
index 2a6bc6c..367867a 100644 (file)
@@ -57,6 +57,8 @@ private slots:
     void setUseCustomFont(const QVariant &);
 
 private:
+    QString sanitizeTopic(const QString& topic);
+
     Ui::TopicWidget ui;
 
     QString _topic;