]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Chck that we don't write more than PIPE_BUF at once on pipes
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 9 Jun 2020 11:19:12 +0000 (13:19 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 9 Jun 2020 11:19:12 +0000 (13:19 +0200)
pdns/dnsdist.cc
pdns/dnsdistdist/doh.cc

index edcefda37002db84c689831ad2c0f69701c6d731..ebc9d88bc3d8e0ece7a9c703594c604a817f4d96 100644 (file)
@@ -638,6 +638,7 @@ try {
 #ifdef HAVE_DNS_OVER_HTTPS
             // DoH query
             du->response = std::string(response, responseLen);
+            static_assert(sizeof(du) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
             ssize_t sent = write(du->rsock, &du, sizeof(du));
             if (sent != sizeof(du)) {
               if (errno == EAGAIN || errno == EWOULDBLOCK) {
index 14373eb3ac0655a50b6e701c1500812e1c954686..bc623435c89de8870ba66675ca9c4f79a36b914e 100644 (file)
@@ -241,6 +241,7 @@ void handleDOHTimeout(DOHUnit* oldDU)
   /* increase the ref counter before sending the pointer */
   oldDU->get();
 
+  static_assert(sizeof(oldDU) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
   ssize_t sent = write(oldDU->rsock, &oldDU, sizeof(oldDU));
   if (sent != sizeof(oldDU)) {
     if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -458,6 +459,7 @@ static int processDOHQuery(DOHUnit* du)
       /* increase the ref counter before sending the pointer */
       du->get();
 
+      static_assert(sizeof(du) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
       ssize_t sent = write(du->rsock, &du, sizeof(du));
       if (sent != sizeof(du)) {
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -670,6 +672,7 @@ static void doh_dispatch_query(DOHServerConfig* dsc, h2o_handler_t* self, h2o_re
     auto ptr = du.release();
     *(ptr->self) = ptr;
     try  {
+      static_assert(sizeof(ptr) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
       ssize_t sent = write(dsc->dohquerypair[0], &ptr, sizeof(ptr));
       if (sent != sizeof(ptr)) {
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -1047,6 +1050,8 @@ static void dnsdistclient(int qsock)
         du->status_code = 500;
         /* increase the ref count before sending the pointer */
         du->get();
+
+        static_assert(sizeof(du) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
         ssize_t sent = write(du->rsock, &du, sizeof(du));
         if (sent != sizeof(du)) {
           if (errno == EAGAIN || errno == EWOULDBLOCK) {