]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Prevent temporary objects in the DNSBackend::get() overrides
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 30 Jan 2020 14:10:42 +0000 (15:10 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 21 Feb 2020 08:59:20 +0000 (09:59 +0100)
modules/gmysqlbackend/smysql.cc
modules/gpgsqlbackend/spgsql.cc
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/ssqlite3.cc

index 9de744c5aa6f4ba4ff90d79ec4f3eb7af4cf0199..74087425e262d9462638628033df0ff56c18e238 100644 (file)
@@ -283,10 +283,10 @@ public:
         g_log<<Logger::Warning<<"Result field at row " << d_residx << " column " << i << " has been truncated, we allocated " << d_res_bind[i].buffer_length << " bytes but at least " << *d_res_bind[i].length << " was needed" << endl;
       }
       if (*d_res_bind[i].is_null) {
-        row.push_back("");
+        row.emplace_back("");
         continue;
       } else {
-        row.push_back(string((char*)d_res_bind[i].buffer, std::min(d_res_bind[i].buffer_length, *d_res_bind[i].length)));
+        row.emplace_back((char*)d_res_bind[i].buffer, std::min(d_res_bind[i].buffer_length, *d_res_bind[i].length));
       }
     }
 
@@ -326,7 +326,7 @@ public:
 
     while(hasNextRow()) {
       nextRow(row);
-      result.push_back(row); 
+      result.push_back(std::move(row));
     }
 
     return this; 
index 7ca9d42230b8017cd2fe7a4d2290b09a93c3f793..68e5be885fc7cf88d576a52ed39185d3481c27c0 100644 (file)
@@ -149,12 +149,12 @@ public:
     row.reserve(PQnfields(d_res));
     for(i=0;i<PQnfields(d_res);i++) {
       if (PQgetisnull(d_res, d_residx, i)) {
-        row.push_back("");
+        row.emplace_back("");
       } else if (PQftype(d_res, i) == 16) { // BOOLEAN
         char *val = PQgetvalue(d_res, d_residx, i);
-        row.push_back(val[0] == 't' ? "1" : "0");
+        row.emplace_back(val[0] == 't' ? "1" : "0");
       } else {
-        row.push_back(string(PQgetvalue(d_res, d_residx, i)));
+        row.emplace_back(PQgetvalue(d_res, d_residx, i));
       }
     }
     d_residx++;
@@ -171,7 +171,7 @@ public:
     if (d_res == NULL) return this;
     result.reserve(d_resnum);
     row_t row;
-    while(hasNextRow()) { nextRow(row); result.push_back(row); }
+    while(hasNextRow()) { nextRow(row); result.push_back(std::move(row)); }
     return this;
   }
 
index d223a0618bb28684830496d50321c916b9d9ece6..3687c61a5a04223ad846f32b98280b0c626a30e5 100644 (file)
@@ -1796,12 +1796,15 @@ bool GSQLBackend::searchComments(const string &pattern, int maxResults, vector<C
   return false;
 }
 
-void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceRecord& r)
+void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)
 {
+  static const int defaultTTL = ::arg().asNum( "default-ttl" );
+
   if (row[1].empty())
-      r.ttl = ::arg().asNum( "default-ttl" );
+      r.ttl = defaultTTL;
   else
       r.ttl=pdns_stou(row[1]);
+
   if(!d_qname.empty())
     r.qname=d_qname;
   else
@@ -1809,10 +1812,13 @@ void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceReco
 
   r.qtype=row[3];
 
-  if (r.qtype==QType::MX || r.qtype==QType::SRV)
+  if (r.qtype==QType::MX || r.qtype==QType::SRV) {
+    r.content.reserve(row[2].size() + row[0].size() + 1);
     r.content=row[2]+" "+row[0];
-  else
-    r.content=row[0];
+  }
+  else {
+    r.content=std::move(row[0]);
+  }
 
   r.last_modified=0;
 
@@ -1826,14 +1832,14 @@ void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceReco
   r.domain_id=pdns_stou(row[4]);
 }
 
-void GSQLBackend::extractComment(const SSqlStatement::row_t& row, Comment& comment)
+void GSQLBackend::extractComment(SSqlStatement::row_t& row, Comment& comment)
 {
   comment.domain_id = pdns_stou(row[0]);
   comment.qname = DNSName(row[1]);
   comment.qtype = row[2];
   comment.modified_at = pdns_stou(row[3]);
-  comment.account = row[4];
-  comment.content = row[5];
+  comment.account = std::move(row[4]);
+  comment.content = std::move(row[5]);
 }
 
 SSqlStatement::~SSqlStatement() { 
index e13290c723db1fc95c88b98e21cce90354062ffe..a98b3a83805841dfb91ffc3a42004a3299c9b3f3 100644 (file)
@@ -241,8 +241,8 @@ public:
 protected:
   bool createDomain(const DNSName &domain, const string &type, const string &masters, const string &account);
   string pattern2SQLPattern(const string& pattern);
-  void extractRecord(const SSqlStatement::row_t& row, DNSResourceRecord& rr);
-  void extractComment(const SSqlStatement::row_t& row, Comment& c);
+  void extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& rr);
+  void extractComment(SSqlStatement::row_t& row, Comment& c);
   bool isConnectionUsable() {
     if (d_db) {
       return d_db->isConnectionUsable();
index 507f2cd2353973e40bbe7250bae9c12870570bc3..0c0eb207aa0901f21fc73d99b9516f5ac258d2ca 100644 (file)
@@ -113,10 +113,10 @@ public:
     for ( int i=0; i<numCols; i++)
     {
       if (sqlite3_column_type(d_stmt,i) == SQLITE_NULL) {
-        row.push_back("");
+        row.emplace_back("");
       } else {
         const char *pData = (const char*) sqlite3_column_text(d_stmt, i);
-        row.push_back(string(pData, sqlite3_column_bytes(d_stmt, i)));
+        row.emplace_back(pData, sqlite3_column_bytes(d_stmt, i));
       }
     }
     d_rc = sqlite3_step(d_stmt);
@@ -128,7 +128,7 @@ public:
     while(hasNextRow()) {
       row_t row;
       nextRow(row);
-      result.push_back(row);
+      result.push_back(std::move(row));
     }
     return this;
   }