Skip to content

Commit

Permalink
Fixed potential buffer corruption in toString of serveral AST (vesoft…
Browse files Browse the repository at this point in the history
…-inc#345)

* fix toString function defect

* address dangleptr's comments

* address dutor's comments
  • Loading branch information
ayyt authored and dutor committed May 13, 2019
1 parent 7aef210 commit b08ea5b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/parser/AdminSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ std::string HostList::toString() const {
buf += std::to_string(host->second);
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -82,7 +84,9 @@ std::string SpaceOptList::toString() const {
buf += item->toString();
buf += ",";
}
buf.resize(buf.size()-1);
if (!buf.empty()) {
buf.resize(buf.size()-1);
}
return buf;
}

Expand Down
8 changes: 6 additions & 2 deletions src/parser/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ std::string SourceNodeList::toString() const {
buf += std::to_string(id);
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -80,7 +82,9 @@ std::string YieldColumns::toString() const {
}
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down
28 changes: 20 additions & 8 deletions src/parser/MaintainSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ std::string CreateTagSentence::toString() const {
buf += "CREATE TAG ";
buf += *name_;
buf += " (";
for (auto *col : columns_->columnSpecs()) {
auto colSpecs = std::move(columns_->columnSpecs());
for (auto *col : colSpecs) {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
Expand All @@ -25,7 +26,9 @@ std::string CreateTagSentence::toString() const {
}
buf += ",";
}
buf.resize(buf.size() - 1);
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
return buf;
}
Expand All @@ -37,7 +40,8 @@ std::string CreateEdgeSentence::toString() const {
buf += "CREATE EDGE ";
buf += *name_;
buf += " (";
for (auto &col : columns_->columnSpecs()) {
auto colSpecs = std::move(columns_->columnSpecs());
for (auto &col : colSpecs) {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
Expand All @@ -47,7 +51,9 @@ std::string CreateEdgeSentence::toString() const {
}
buf += ",";
}
buf.resize(buf.size() - 1);
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
return buf;
}
Expand All @@ -58,7 +64,8 @@ std::string AlterTagOptItem::toString() const {
buf.reserve(256);
buf += getOptTypeStr();
buf += " (";
for (auto &col : columns_->columnSpecs()) {
auto colSpecs = std::move(columns_->columnSpecs());
for (auto &col : colSpecs) {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
Expand All @@ -68,7 +75,9 @@ std::string AlterTagOptItem::toString() const {
}
buf += ",";
}
buf.resize(buf.size() - 1);
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
return buf;
}
Expand Down Expand Up @@ -106,7 +115,8 @@ std::string AlterEdgeSentence::toString() const {
buf += "ALTER EDGE ";
buf += *name_;
buf += "(";
for (auto &col : columns_->columnSpecs()) {
auto colSpecs = std::move(columns_->columnSpecs());
for (auto &col : colSpecs) {
buf += *col->name();
buf += " ";
buf += columnTypeToString(col->type());
Expand All @@ -116,7 +126,9 @@ std::string AlterEdgeSentence::toString() const {
}
buf += ",";
}
buf.resize(buf.size() - 1);
if (!colSpecs.empty()) {
buf.resize(buf.size() - 1);
}
buf += ")";
return buf;
}
Expand Down
29 changes: 21 additions & 8 deletions src/parser/MutateSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ std::string PropertyList::toString() const {
buf += *prop;
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -43,8 +45,9 @@ std::string VertexTagList::toString() const {
buf += item->toString();
buf += ",";
}
buf.resize(buf.size() - 1);

if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand All @@ -56,7 +59,9 @@ std::string ValueList::toString() const {
buf += expr->toString();
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand All @@ -80,7 +85,9 @@ std::string VertexRowList::toString() const {
buf += item->toString();
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -123,7 +130,9 @@ std::string EdgeRowList::toString() const {
buf += item->toString();
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -161,7 +170,9 @@ std::string UpdateList::toString() const {
buf += item->toString();
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down Expand Up @@ -236,7 +247,9 @@ std::string EdgeList::toString() const {
buf += std::to_string(edge.second);
buf += ",";
}
buf.resize(buf.size() - 1);
if (!buf.empty()) {
buf.resize(buf.size() - 1);
}
return buf;
}

Expand Down

0 comments on commit b08ea5b

Please sign in to comment.