Skip to content

Commit

Permalink
Fix dbtools handling of quote marks in attribute/flag names. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnw committed Aug 25, 2018
1 parent fdf5a35 commit f585ed6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGES.187.md
Expand Up @@ -37,6 +37,7 @@ Fixes

* `connrecord()` returns an error if extended connection logging is disabled. [SW]
* `connlog()` didn't handle future dates very well. [SW]
* dbtools programs couludn't handle attributes with quote marks in the name. Reported by [MG]. [SW,1228]

Version 1.8.7 patchlevel 0 Aug 10 2018
======================================
Expand Down
16 changes: 8 additions & 8 deletions dbtools/db_labelsv1.cpp
Expand Up @@ -266,7 +266,7 @@ write_flags(std::ostream &out, const flagmap &flags)
out << "flagcount " << canon.size() << '\n';
for (const auto &name : canon) {
const auto &flag = flags.find(name)->second;
out << " name \"" << flag.name << "\"\n";
db_write_labeled_string(out, " name", flag.name);
if (flag.letter) {
if (flag.letter == '"') {
out << R"( letter "\"")" << '\n';
Expand All @@ -284,8 +284,8 @@ write_flags(std::ostream &out, const flagmap &flags)
out << "flagaliascount " << aliases.size() << '\n';
for (const auto &name : aliases) {
const auto &flag = flags.find(name)->second;
out << " name \"" << flag.name << "\"\n";
out << " alias \"" << name << "\"\n";
db_write_labeled_string(out, " name", flag.name);
db_write_labeled_string(out, " alias", name);
}
}

Expand All @@ -306,7 +306,7 @@ write_db_attribs(std::ostream &out, const attrmap &attribs)
out << "attrcount " << canon.size() << '\n';
for (const auto &name : canon) {
const auto &attr = attribs.find(name)->second;
out << " name \"" << attr.name << "\"\n";
db_write_labeled_string(out, " name", attr.name);
out << " flags \"" << join_words(attr.flags) << "\"\n";
out << " creator #" << attr.creator << '\n';
out << " data \"\"\n";
Expand All @@ -315,8 +315,8 @@ write_db_attribs(std::ostream &out, const attrmap &attribs)
out << "attraliascount " << aliases.size() << '\n';
for (const auto &name : aliases) {
const auto &attr = attribs.find(name)->second;
out << " name \"" << attr.name << "\"\n";
out << " alias \"" << name << "\"\n";
db_write_labeled_string(out, " name", attr.name);
db_write_labeled_string(out, " alias", name);
}
}

Expand All @@ -326,7 +326,7 @@ write_locks(std::ostream &out, const lockmap &locks)
out << "lockcount " << locks.size() << '\n';
for (const auto &l : locks) {
const auto &lk = l.second;
out << " type \"" << lk.type << "\"\n";
db_write_labeled_string(out, " type", lk.type);
out << " creator #" << lk.creator << '\n';
out << " flags \"" << join_words(lk.flags) << "\"\n";
out << " derefs " << lk.derefs << '\n';
Expand All @@ -340,7 +340,7 @@ write_obj_attribs(std::ostream &out, const attrmap &attribs)
out << "attrcount " << attribs.size() << '\n';
for (const auto &a : attribs) {
const auto &attr = a.second;
out << " name \"" << attr.name << "\"\n";
db_write_labeled_string(out, " name", attr.name);
out << " owner #" << attr.creator << '\n';
out << " flags \"" << join_words(attr.flags) << "\"\n";
out << " derefs " << attr.derefs << '\n';
Expand Down
43 changes: 27 additions & 16 deletions dbtools/utils.cpp
Expand Up @@ -39,33 +39,44 @@ std::string
join_words(const stringset &words)
{
std::ostringstream out;
bool first = true;

for (const auto &w : words) {
out << w;
out << ' ';
}

auto res = out.str();

if (res.back() == ' ') {
res.pop_back();
if (first) {
first = false;
} else {
out << ' ';
}
for (char c : w) {
if (c == '"' || c == '\\') {
out << '\\';
}
out << c;
}
}

return res;
return out.str();
}

std::string
join_words(const stringvec &words)
{
std::string res;
std::ostringstream out;
bool first = true;

for (auto i = words.begin(); i != words.end(); ++i) {
if (i != words.begin()) {
res += ' ';
for (const auto &w : words) {
if (first) {
first = false;
} else {
out << ' ';
}
for (char c : w) {
if (c == '"' || c == '\\') {
out << '\\';
}
out << c;
}
res += *i;
}
return res;
return out.str();
}

std::string
Expand Down

0 comments on commit f585ed6

Please sign in to comment.