summaryrefslogtreecommitdiff
path: root/AK/String.cpp
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-06-13 16:28:48 +0300
committerAndreas Kling <awesomekling@gmail.com>2019-06-14 06:24:02 +0200
commit3e326de8fa813f7eb88cb2a376f8168f21956cc6 (patch)
tree1c2106905d58ae00fa86241151d9288b802eda55 /AK/String.cpp
parente585ed48b0b3e89a8bb4a805b568b7627c42c72b (diff)
downloadserenity-3e326de8fa813f7eb88cb2a376f8168f21956cc6.zip
AK: Fix nullptr dereference in String::matches().
In case cp and mp were never set, we should not try to use them.
Diffstat (limited to 'AK/String.cpp')
-rw-r--r--AK/String.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/AK/String.cpp b/AK/String.cpp
index e2d5f3d2c4..d0ca1b4909 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -253,9 +253,11 @@ bool String::match_helper(const StringView& mask) const
} else if ((mask_ptr < mask_end) && ((*mask_ptr == *string_ptr) || (*mask_ptr == '?'))) {
mask_ptr++;
string_ptr++;
- } else {
+ } else if ((cp != nullptr) && (mp != nullptr)) {
mask_ptr = mp;
string_ptr = cp++;
+ } else {
+ break;
}
}
@@ -263,8 +265,8 @@ bool String::match_helper(const StringView& mask) const
while ((mask_ptr < mask_end) && (*mask_ptr == '*'))
mask_ptr++;
- // If we 'ate' all of the mask then we match.
- return mask_ptr == mask_end;
+ // If we 'ate' all of the mask and the string then we match.
+ return (mask_ptr == mask_end) && !*string_ptr;
}
}