[6.0] cbfb8db0a Add VTCP_Assert() in various places that call read() and write()

Reza Naghibi reza at naghibi.com
Thu Apr 22 15:55:07 UTC 2021


commit cbfb8db0a68ef2def278cf2ecaeeeef900213fe6
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Oct 7 16:17:44 2020 +0200

    Add VTCP_Assert() in various places that call read() and write()
    
    This adds VTCP_Assert() on the result of read and write calls that deals
    with TCP sockets.
    
     Conflicts:
            bin/varnishd/proxy/cache_proxy_proto.c

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index b488c1525..5259c6a81 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -228,6 +228,7 @@ vbp_write(struct vbp_target *vt, int *sock, const void *buf, size_t len)
 	int i;
 
 	i = write(*sock, buf, len);
+	VTCP_Assert(i);
 	if (i != len) {
 		if (i < 0) {
 			vt->err_xmit |= 1;
@@ -367,6 +368,7 @@ vbp_poke(struct vbp_target *vt)
 			    sizeof vt->resp_buf - rlen);
 		else
 			i = read(s, buf, sizeof buf);
+		VTCP_Assert(i);
 		if (i <= 0) {
 			if (i < 0)
 				bprintf(vt->resp_buf, "Read error %d (%s)",
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 12bcaa545..659bcad19 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -33,6 +33,8 @@
 #include "cache/cache_filter.h"
 #include "cache_http1.h"
 
+#include "vtcp.h"
+
 /*--------------------------------------------------------------------*/
 
 static int v_matchproto_(vdp_bytes_f)
@@ -74,7 +76,7 @@ v1d_error(struct req *req, const char *msg)
 	VSLb(req->vsl, SLT_RespReason, "Internal Server Error");
 
 	req->wrk->stats->client_resp_500++;
-	(void)write(req->sp->fd, r_500, sizeof r_500 - 1);
+	VTCP_Assert(write(req->sp->fd, r_500, sizeof r_500 - 1));
 	req->doclose = SC_TX_EOF;
 }
 
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index 224298b01..ea31f4b55 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -37,6 +37,7 @@
 #include <stdio.h>
 
 #include "cache_http1.h"
+#include "vtcp.h"
 
 #include "VSC_vbe.h"
 
@@ -49,10 +50,12 @@ rdf(int fd0, int fd1, uint64_t *pcnt)
 	char buf[BUFSIZ], *p;
 
 	i = read(fd0, buf, sizeof buf);
+	VTCP_Assert(i);
 	if (i <= 0)
 		return (1);
 	for (p = buf; i > 0; i -= j, p += j) {
 		j = write(fd1, p, i);
+		VTCP_Assert(j);
 		if (j <= 0)
 			return (1);
 		*pcnt += j;
@@ -96,6 +99,7 @@ V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a)
 	if (req->htc->pipeline_b != NULL) {
 		j = write(fd,  req->htc->pipeline_b,
 		    req->htc->pipeline_e - req->htc->pipeline_b);
+		VTCP_Assert(j);
 		if (j < 0)
 			return;
 		req->htc->pipeline_b = NULL;
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 9d3683845..de1083592 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -39,6 +39,7 @@
 
 #include "vend.h"
 #include "vtim.h"
+#include "vtcp.h"
 
 static const char h2_resp_101[] =
 	"HTTP/1.1 101 Switching Protocols\r\n"
@@ -256,6 +257,7 @@ h2_ou_session(struct worker *wrk, struct h2_sess *h2,
 	}
 
 	sz = write(h2->sess->fd, h2_resp_101, strlen(h2_resp_101));
+	VTCP_Assert(sz);
 	if (sz != strlen(h2_resp_101)) {
 		VSLb(h2->vsl, SLT_Debug, "H2: Upgrade: Error writing 101"
 		    " response: %s\n", strerror(errno));
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 64935686d..09b60295b 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -620,7 +620,7 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 	struct suckaddr *sac, *sas;
 	char ha[VTCP_ADDRBUFSIZE];
 	char pa[VTCP_PORTBUFSIZE];
-	int proto;
+	int proto, r;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	assert(version == 1 || version == 2);
@@ -667,7 +667,9 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 		WRONG("Wrong proxy version");
 
 	AZ(VSB_finish(vsb));
-	(void)VSB_tofile(vsb, fd);	// XXX: Error handling ?
+	r = write(fd, VSB_data(vsb), VSB_len(vsb));
+	VTCP_Assert(r);
+
 	if (!DO_DEBUG(DBG_PROTOCOL)) {
 		VSB_delete(vsb);
 		return;


More information about the varnish-commit mailing list