Skip to content

Commit 17a8482

Browse files
author
Martin Hansson
committed
Bug#27572258 CRASH WITH REGEXP_SUBSTR...
If the pattern is NULL, there is no regular expression to compile, and the pointer to it is nullptr. This is fine, but we must check for that value and return (SQL) NULL. Change-Id: Ib66c32f361fe50f4a56a5f99a3baae8309d27bab
1 parent f7d9ff5 commit 17a8482

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

sql/regexp/regexp_engine.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -43,15 +43,14 @@ UBool QueryNotKilled(const void *thd, int32_t) {
4343

4444
const char *icu_version_string() { return U_ICU_VERSION; }
4545

46-
bool Regexp_engine::Reset(String *subject) {
46+
void Regexp_engine::Reset(String *subject) {
4747
auto usubject = pointer_cast<const UChar *>(subject->ptr());
4848
int length = subject->length() / sizeof(UChar);
4949

5050
DBUG_ASSERT(is_aligned(usubject));
5151
DBUG_ASSERT(subject->charset() == regexp_lib_charset);
5252
uregex_setText(m_re, usubject, length, &m_error_code);
5353
m_current_subject = subject;
54-
return false;
5554
}
5655

5756
bool Regexp_engine::Matches(int start, int occurrence) {

sql/regexp/regexp_engine.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SQL_REGEXP_REGEXP_ENGINE_H_
22
#define SQL_REGEXP_REGEXP_ENGINE_H_
33

4-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License, version 2.0,
@@ -110,7 +110,7 @@ class Regexp_engine {
110110
Resets the engine with a new subject string.
111111
@param subject The new string to match the regular expression against.
112112
*/
113-
bool Reset(String *subject);
113+
virtual void Reset(String *subject);
114114

115115
/**
116116
Tries to find match number `occurrence` in the string, starting on

sql/regexp/regexp_facade.cc

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -55,15 +55,9 @@ String *EvalExprToCharset(Item *expr, String *out) {
5555
}
5656

5757
bool Regexp_facade::SetPattern(Item *pattern_expr) {
58-
/*
59-
The pattern is NULL, but that's fine. Since it's the facade's job to
60-
handle NULL values, we leverage the fact that any matching against NULL
61-
will have the result NULL and don't involve the Regexp_engine class at
62-
all.
63-
*/
6458
if (pattern_expr == nullptr) {
6559
m_engine = nullptr;
66-
return false;
60+
return true;
6761
}
6862
if (!pattern_expr->const_item() || // Non-constant pattern, see above.
6963
m_engine == nullptr) { // Called for the first time.
@@ -117,7 +111,8 @@ String *Regexp_facade::Replace(Item *subject_expr, Item *replacement_expr,
117111

118112
String *Regexp_facade::Substr(Item *subject_expr, int start, int occurrence,
119113
String *result) {
120-
if (Reset(subject_expr) || !m_engine->Matches(start - 1, occurrence)) {
114+
if (Reset(subject_expr)) return nullptr;
115+
if (!m_engine->Matches(start - 1, occurrence)) {
121116
m_engine->CheckError();
122117
return nullptr;
123118
}

0 commit comments

Comments
 (0)