Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 1ec86b6

Browse files
committed
null check before attempting to read COPY options
1 parent 6cc5559 commit 1ec86b6

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/parser/postgresparser.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,31 +1526,35 @@ parser::CopyStatement *PostgresParser::CopyTransform(CopyStmt *root) {
15261526

15271527
// Handle options
15281528
ListCell *cell = nullptr;
1529-
for_each_cell(cell, root->options->head) {
1530-
auto *def_elem = reinterpret_cast<DefElem *>(cell->data.ptr_value);
15311529

1532-
// Check delimiter
1533-
if (strncmp(def_elem->defname, kDelimiterTok, sizeof(kDelimiterTok)) == 0) {
1534-
auto *delimiter_val = reinterpret_cast<value *>(def_elem->arg);
1535-
result->delimiter = *delimiter_val->val.str;
1536-
}
1530+
if (root->options != nullptr) {
1531+
for_each_cell(cell, root->options->head) {
1532+
auto *def_elem = reinterpret_cast<DefElem *>(cell->data.ptr_value);
15371533

1538-
// Check format
1539-
if (strncmp(def_elem->defname, kFormatTok, sizeof(kFormatTok)) == 0) {
1540-
auto *format_val = reinterpret_cast<value *>(def_elem->arg);
1541-
result->format = StringToExternalFileFormat(format_val->val.str);
1542-
}
1534+
// Check delimiter
1535+
if (strncmp(def_elem->defname, kDelimiterTok, sizeof(kDelimiterTok)) ==
1536+
0) {
1537+
auto *delimiter_val = reinterpret_cast<value *>(def_elem->arg);
1538+
result->delimiter = *delimiter_val->val.str;
1539+
}
15431540

1544-
// Check quote
1545-
if (strncmp(def_elem->defname, kQuoteTok, sizeof(kQuoteTok)) == 0) {
1546-
auto *quote_val = reinterpret_cast<value *>(def_elem->arg);
1547-
result->quote = *quote_val->val.str;
1548-
}
1541+
// Check format
1542+
if (strncmp(def_elem->defname, kFormatTok, sizeof(kFormatTok)) == 0) {
1543+
auto *format_val = reinterpret_cast<value *>(def_elem->arg);
1544+
result->format = StringToExternalFileFormat(format_val->val.str);
1545+
}
1546+
1547+
// Check quote
1548+
if (strncmp(def_elem->defname, kQuoteTok, sizeof(kQuoteTok)) == 0) {
1549+
auto *quote_val = reinterpret_cast<value *>(def_elem->arg);
1550+
result->quote = *quote_val->val.str;
1551+
}
15491552

1550-
// Check escape
1551-
if (strncmp(def_elem->defname, kEscapeTok, sizeof(kEscapeTok)) == 0) {
1552-
auto *escape_val = reinterpret_cast<value *>(def_elem->arg);
1553-
result->escape = *escape_val->val.str;
1553+
// Check escape
1554+
if (strncmp(def_elem->defname, kEscapeTok, sizeof(kEscapeTok)) == 0) {
1555+
auto *escape_val = reinterpret_cast<value *>(def_elem->arg);
1556+
result->escape = *escape_val->val.str;
1557+
}
15541558
}
15551559
}
15561560

0 commit comments

Comments
 (0)