Added range check for extractGroups function

This commit is contained in:
Alexey Milovidov 2020-05-08 02:31:15 +03:00
parent 2cb4c91c02
commit 1f0d95e5c3
4 changed files with 30 additions and 0 deletions

View File

@ -18,6 +18,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
extern const int BAD_ARGUMENTS;
}
@ -64,8 +65,15 @@ public:
const auto regexp = Regexps::get<false, false>(needle);
const auto & re2 = regexp->getRE2();
if (!re2)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
const size_t groups_count = re2->NumberOfCapturingGroups();
if (!groups_count)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
// Including 0-group, which is the whole regexp.
PODArrayWithStackMemory<re2_st::StringPiece, 128> matched_groups(groups_count + 1);

View File

@ -18,6 +18,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
extern const int BAD_ARGUMENTS;
}
@ -64,8 +65,15 @@ public:
const auto regexp = Regexps::get<false, false>(needle);
const auto & re2 = regexp->getRE2();
if (!re2)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
const size_t groups_count = re2->NumberOfCapturingGroups();
if (!groups_count)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
// Including 0-group, which is the whole regexp.
PODArrayWithStackMemory<re2_st::StringPiece, 128> matched_groups(groups_count + 1);

View File

@ -0,0 +1,14 @@
SELECT extractGroups('hello', ''); -- { serverError 69 }
SELECT extractAllGroups('hello', ''); -- { serverError 69 }
SELECT extractGroups('hello', ' '); -- { serverError 36 }
SELECT extractAllGroups('hello', ' '); -- { serverError 36 }
SELECT extractGroups('hello', '\0'); -- { serverError 36 }
SELECT extractAllGroups('hello', '\0'); -- { serverError 36 }
SELECT extractGroups('hello', 'world'); -- { serverError 36 }
SELECT extractAllGroups('hello', 'world'); -- { serverError 36 }
SELECT extractGroups('hello', 'hello|world'); -- { serverError 36 }
SELECT extractAllGroups('hello', 'hello|world'); -- { serverError 36 }