From: Remi Gacogne Date: Tue, 9 Jun 2020 11:19:12 +0000 (+0200) Subject: dnsdist: Chck that we don't write more than PIPE_BUF at once on pipes X-Git-Tag: dnsdist-1.5.0-rc3~8^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b422afcda6bed1c53cdc1b334fa14cb162fbb227;p=thirdparty%2Fpdns.git dnsdist: Chck that we don't write more than PIPE_BUF at once on pipes --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index edcefda370..ebc9d88bc3 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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) { diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 14373eb3ac..bc623435c8 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -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) {