Permalink
Browse files

Fix dbtools handling of quote marks in attribute/flag names. Closes #…

  • Loading branch information...
shawnw committed Aug 25, 2018
1 parent fdf5a35 commit f585ed69daff1bdc1da1ce468c3ba297c3da01de
Showing with 36 additions and 24 deletions.
  1. +1 −0 CHANGES.187.md
  2. +8 −8 dbtools/db_labelsv1.cpp
  3. +27 −16 dbtools/utils.cpp
@@ -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
======================================
@@ -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';
@@ -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);
}
}
@@ -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";
@@ -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);
}
}
@@ -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';
@@ -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';
@@ -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

0 comments on commit f585ed6

Please sign in to comment.