fix use-after-free [#CLICKHOUSE-3101]

This commit is contained in:
Alexey Zatelepin 2019-03-15 21:52:45 +03:00
parent a030ce90b5
commit a2debdb724
3 changed files with 24 additions and 6 deletions

View File

@ -25,7 +25,7 @@ namespace Poco { class Logger; }
namespace DB
{
struct ColumnsDescription;
class ColumnsDescription;
/// State of query processing.
struct QueryState

View File

@ -111,6 +111,20 @@ ColumnsDescription::ColumnsDescription(NamesAndTypesList ordinary)
add(ColumnDescription(std::move(elem.name), std::move(elem.type)));
}
ColumnsDescription::ColumnsDescription(const ColumnsDescription & other)
: columns(other.columns)
{
for (auto it = columns.begin(); it != columns.end(); ++it)
name_to_column.emplace(it->name, it);
}
ColumnsDescription & ColumnsDescription::operator=(const ColumnsDescription & other)
{
if (&other != this)
*this = ColumnsDescription(other);
return *this;
}
/// We are trying to find first column from end with name `column_name` or with a name beginning with `column_name` and ".".
/// For example "fruits.bananas"

View File

@ -29,15 +29,15 @@ struct ColumnDescription
void readText(ReadBuffer & buf);
};
struct ColumnsDescription
class ColumnsDescription
{
private:
std::list<ColumnDescription> columns;
std::unordered_map<String, std::list<ColumnDescription>::iterator> name_to_column;
public:
ColumnsDescription() = default;
explicit ColumnsDescription(NamesAndTypesList ordinary_);
ColumnsDescription(const ColumnsDescription & other);
ColumnsDescription & operator=(const ColumnsDescription & other);
ColumnsDescription(ColumnsDescription &&) noexcept = default;
ColumnsDescription & operator=(ColumnsDescription &&) noexcept = default;
/// `after_column` can be a Nested column name;
void add(ColumnDescription column, const String & after_column = String());
@ -80,6 +80,10 @@ public:
static ColumnsDescription parse(const String & str);
static const ColumnsDescription * loadFromContext(const Context & context, const String & db, const String & table);
private:
std::list<ColumnDescription> columns;
std::unordered_map<String, std::list<ColumnDescription>::iterator> name_to_column;
};
}