Prevent huge memory allocation for Damerau-Levenshtein algo

This commit is contained in:
Martchus 2018-05-11 16:15:16 +02:00
parent 5e8d8cb7d1
commit b69b841fa3
1 changed files with 4 additions and 0 deletions

View File

@ -1209,6 +1209,10 @@ string ArgumentParser::findSuggestions(int argc, const char *const *argv, unsign
// determine the unknown/misspelled argument // determine the unknown/misspelled argument
const auto *unknownArg(*reader.argv); const auto *unknownArg(*reader.argv);
auto unknownArgSize(strlen(unknownArg)); auto unknownArgSize(strlen(unknownArg));
// -> refuse suggestions for long args to prevent huge memory allocation for Damerau-Levenshtein algo
if (unknownArgSize > 16) {
return string();
}
// -> remove dashes since argument names internally don't have them // -> remove dashes since argument names internally don't have them
if (unknownArgSize >= 2 && unknownArg[0] == '-' && unknownArg[1] == '-') { if (unknownArgSize >= 2 && unknownArg[0] == '-' && unknownArg[1] == '-') {
unknownArg += 2; unknownArg += 2;