common: Fix whitespace CTCP ignore invalid index
authorShane Synan <digitalcircuit36939@gmail.com>
Sat, 1 Sep 2018 21:17:33 +0000 (16:17 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 3 Sep 2018 20:12:02 +0000 (22:12 +0200)
When constructing a CTCP ignore, check that splitting on whitespace
results in non-empty list before taking from the list.  If it's
empty, fall back to assuming any valid sender, i.e. "*"/".*"
depending on whether the rule is set as wildcard or regex.

This fixes issues when receiving a CTCP with an invalid CTCP ignore
rule such as "  ".

src/common/ignorelistmanager.h

index 7bf4bab..baf3cc1 100644 (file)
@@ -122,10 +122,27 @@ public:
                 // This is not performance-intensive; sticking with QRegExp for Qt 4 is fine
                 // Split based on whitespace characters
                 QStringList split(contents().split(QRegExp("\\s+"), QString::SkipEmptyParts));
                 // This is not performance-intensive; sticking with QRegExp for Qt 4 is fine
                 // Split based on whitespace characters
                 QStringList split(contents().split(QRegExp("\\s+"), QString::SkipEmptyParts));
-                // Match on the first item
-                _cacheCtcpSender = split.takeFirst();
-                // Track the rest as CTCP types to ignore
-                _cacheCtcpTypes = split;
+                // Match on the first item, handling empty rules/matches
+                if (!split.isEmpty()) {
+                    // Take the first item as the sender
+                    _cacheCtcpSender = split.takeFirst();
+                    // Track the rest as CTCP types to ignore
+                    _cacheCtcpTypes = split;
+                }
+                else {
+                    // No match found - this can happen if a pure whitespace CTCP ignore rule is
+                    // created.  Fall back to matching all senders.
+                    if (_isRegEx) {
+                        // RegEx match everything
+                        _cacheCtcpSender = ".*";
+                    }
+                    else {
+                        // Wildcard match everything
+                        _cacheCtcpSender = "*";
+                    }
+                    // Clear the types (split is already empty)
+                    _cacheCtcpTypes = split;
+                }
             }
             _type = type;
         }
             }
             _type = type;
         }