AK: Fix nullptr dereference in String::matches().

In case cp and mp were never set, we should not try
to use them.
This commit is contained in:
Sergey Bugaev 2019-06-13 16:28:48 +03:00 committed by Andreas Kling
parent e585ed48b0
commit 3e326de8fa
Notes: sideshowbarker 2024-07-19 13:37:51 +09:00

View file

@ -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;
}
}