[master] 3969a9c02 spatch to replace VSLb(..., "%s", s) with VSLbs(..., TOSTRAND(s))

Nils Goroll nils.goroll at uplex.de
Tue Jul 26 10:00:12 UTC 2022


commit 3969a9c0241a7ba94e1360ad25f90bf908bf55f5
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sun Jul 24 13:46:14 2022 +0200

    spatch to replace VSLb(..., "%s", s) with VSLbs(..., TOSTRAND(s))
    
    Added coccinelle patch and applied it.
    
    Indentation polished manually - can we teach spatch our cstyle?
    
    Ref 5e5b442f53d27cfa6000f9bc7694fbce5a46af5c

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index fde7e29a9..4dcf0d8fe 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -1140,7 +1140,7 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
 	bo->is_hitmiss = req->is_hitmiss;
 
 	VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how);
-	VSLb(bo->vsl, SLT_VCL_use, "%s", VCL_Name(bo->vcl));
+	VSLbs(bo->vsl, SLT_VCL_use, TOSTRAND(VCL_Name(bo->vcl)));
 	VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how);
 
 	THR_SetBusyobj(bo);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 0fcb05739..a8bd61f5b 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -196,7 +196,7 @@ HSH_AddString(struct req *req, void *ctx, const char *str)
 	AN(ctx);
 	if (str != NULL) {
 		VSHA256_Update(ctx, str, strlen(str));
-		VSLb(req->vsl, SLT_Hash, "%s", str);
+		VSLbs(req->vsl, SLT_Hash, TOSTRAND(str));
 	} else
 		VSHA256_Update(ctx, &str, 1);
 }
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 61849ab04..7d08808bb 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -415,7 +415,7 @@ http_PutField(struct http *to, int field, const char *string)
 	p = WS_Copy(to->ws, string, -1);
 	if (p == NULL) {
 		http_fail(to);
-		VSLb(to->vsl, SLT_LostHeader, "%s", string);
+		VSLbs(to->vsl, SLT_LostHeader, TOSTRAND(string));
 		return;
 	}
 	http_SetH(to, field, p);
@@ -535,7 +535,8 @@ http_CollectHdrSep(struct http *hp, hdr_t hdr, const char *sep)
 			x = Tlen(hp->hd[f]);
 			if (b + x >= e) {
 				http_fail(hp);
-				VSLb(hp->vsl, SLT_LostHeader, "%s", hdr + 1);
+				VSLbs(hp->vsl, SLT_LostHeader,
+				    TOSTRAND(hdr + 1));
 				WS_Release(hp->ws, 0);
 				return;
 			}
@@ -557,7 +558,7 @@ http_CollectHdrSep(struct http *hp, hdr_t hdr, const char *sep)
 
 		if (b + lsep + x >= e) {
 			http_fail(hp);
-			VSLb(hp->vsl, SLT_LostHeader, "%s", hdr + 1);
+			VSLbs(hp->vsl, SLT_LostHeader, TOSTRAND(hdr + 1));
 			WS_Release(hp->ws, 0);
 			return;
 		}
@@ -1441,7 +1442,7 @@ http_CopyHome(const struct http *hp)
 		p = WS_Copy(hp->ws, hp->hd[u].b, l + 1L);
 		if (p == NULL) {
 			http_fail(hp);
-			VSLb(hp->vsl, SLT_LostHeader, "%s", hp->hd[u].b);
+			VSLbs(hp->vsl, SLT_LostHeader, TOSTRAND(hp->hd[u].b));
 			return;
 		}
 		hp->hd[u].b = p;
@@ -1457,7 +1458,7 @@ http_SetHeader(struct http *to, const char *header)
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	if (to->nhd >= to->shd) {
-		VSLb(to->vsl, SLT_LostHeader, "%s", header);
+		VSLbs(to->vsl, SLT_LostHeader, TOSTRAND(header));
 		http_fail(to);
 		return;
 	}
@@ -1511,14 +1512,14 @@ http_TimeHeader(struct http *to, const char *fmt, vtim_real now)
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	if (to->nhd >= to->shd) {
-		VSLb(to->vsl, SLT_LostHeader, "%s", fmt);
+		VSLbs(to->vsl, SLT_LostHeader, TOSTRAND(fmt));
 		http_fail(to);
 		return;
 	}
 	p = WS_Alloc(to->ws, strlen(fmt) + VTIM_FORMAT_SIZE);
 	if (p == NULL) {
 		http_fail(to);
-		VSLb(to->vsl, SLT_LostHeader, "%s", fmt);
+		VSLbs(to->vsl, SLT_LostHeader, TOSTRAND(fmt));
 		return;
 	}
 	strcpy(p, fmt);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 81217159f..857b29cf8 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -1137,7 +1137,7 @@ CNT_Embark(struct worker *wrk, struct req *req)
 		VCL_Refresh(&wrk->wpriv->vcl);
 		req->vcl = wrk->wpriv->vcl;
 		wrk->wpriv->vcl = NULL;
-		VSLb(req->vsl, SLT_VCL_use, "%s", VCL_Name(req->vcl));
+		VSLbs(req->vsl, SLT_VCL_use, TOSTRAND(VCL_Name(req->vcl)));
 	}
 
 	AN(req->vcl);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 312ca0d01..dff0692af 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -123,7 +123,7 @@ VPI_acl_log(VRT_CTX, const char *msg)
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(msg);
 	if (ctx->vsl != NULL)
-		VSLb(ctx->vsl, SLT_VCL_acl, "%s", msg);
+		VSLbs(ctx->vsl, SLT_VCL_acl, TOSTRAND(msg));
 	else
 		VSL(SLT_VCL_acl, 0, "%s", msg);
 }
@@ -602,7 +602,7 @@ VRT_SetHdr(VRT_CTX, VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 	if (u <= l) {
 		WS_Release(hp->ws, 0);
 		WS_MarkOverflow(hp->ws);
-		VSLb(ctx->vsl, SLT_LostHeader, "%s", hs->what + 1);
+		VSLbs(ctx->vsl, SLT_LostHeader, TOSTRAND(hs->what + 1));
 		return;
 	}
 	b = WS_Reservation(hp->ws);
@@ -611,7 +611,8 @@ VRT_SetHdr(VRT_CTX, VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 		if (p == NULL) {
 			WS_Release(hp->ws, 0);
 			WS_MarkOverflow(hp->ws);
-			VSLb(ctx->vsl, SLT_LostHeader, "%s", hs->what + 1);
+			VSLbs(ctx->vsl, SLT_LostHeader,
+			    TOSTRAND(hs->what + 1));
 			return;
 		}
 	} else {
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index ac6e9a9b9..becac9dc2 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -240,7 +240,7 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl)
 	const struct vfilter *vp;
 
 	AN(fl);
-	VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
+	VSLbs(vc->wrk->vsl, SLT_Filters, TOSTRAND(fl));
 
 	while (1) {
 		vp = vcl_filter_list_iter(1, &vrt_filters, &vcl->filters, &fl);
@@ -260,7 +260,7 @@ VCL_StackVDP(struct req *req, const struct vcl *vcl, const char *fl)
 	struct vrt_ctx ctx[1];
 
 	AN(fl);
-	VSLb(req->vsl, SLT_Filters, "%s", fl);
+	VSLbs(req->vsl, SLT_Filters, TOSTRAND(fl));
 	INIT_OBJ(ctx, VRT_CTX_MAGIC);
 	VCL_Req2Ctx(ctx, req);
 
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 070822f36..a71edc9a3 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -555,9 +555,10 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 	wrk->cur_method = method;
 	wrk->seen_methods |= method;
 	AN(ctx.vsl);
-	VSLb(ctx.vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
+	VSLbs(ctx.vsl, SLT_VCL_call, TOSTRAND(VCL_Method_Name(method)));
 	func(&ctx, VSUB_STATIC, NULL);
-	VSLb(ctx.vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
+	VSLbs(ctx.vsl, SLT_VCL_return,
+	    TOSTRAND(VCL_Return_Name(wrk->handling)));
 	wrk->cur_method |= 1;		// Magic marker
 	if (wrk->handling == VCL_RET_FAIL)
 		wrk->stats->vcl_fail++;
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 2db4f8efa..46c663eb7 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -72,7 +72,7 @@ v1d_error(struct req *req, const char *msg)
 	    "Server: Varnish\r\n"
 	    "Connection: close\r\n\r\n";
 
-	VSLb(req->vsl, SLT_Error, "%s", msg);
+	VSLbs(req->vsl, SLT_Error, TOSTRAND(msg));
 	VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
 	VSLb(req->vsl, SLT_RespStatus, "500");
 	VSLb(req->vsl, SLT_RespReason, "Internal Server Error");
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 641f6e805..cc61649fd 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -199,7 +199,7 @@ http1_minimal_response(struct req *req, uint16_t status)
 
 	VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
 	VSLb(req->vsl, SLT_RespStatus, "%03d", status);
-	VSLb(req->vsl, SLT_RespReason, "%s", reason);
+	VSLbs(req->vsl, SLT_RespReason, TOSTRAND(reason));
 
 	if (status >= 400)
 		req->err_code = status;
diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c
index 69c3099d0..7d057fe2e 100644
--- a/bin/varnishd/http1/cache_http1_vfp.c
+++ b/bin/varnishd/http1/cache_http1_vfp.c
@@ -77,8 +77,8 @@ v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, ssize_t len)
 		i = read(*htc->rfd, p, len);
 		if (i < 0) {
 			VTCP_Assert(i);
-			VSLb(vc->wrk->vsl, SLT_FetchError,
-			    "%s", VAS_errtxt(errno));
+			VSLbs(vc->wrk->vsl, SLT_FetchError,
+			    TOSTRAND(VAS_errtxt(errno)));
 			return (i);
 		}
 		if (i == 0)
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index f5e08b7da..a19e936d5 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -181,7 +181,8 @@ h2_minimal_response(struct req *req, uint16_t status)
 
 	VSLb(req->vsl, SLT_RespProtocol, "HTTP/2.0");
 	VSLb(req->vsl, SLT_RespStatus, "%03d", status);
-	VSLb(req->vsl, SLT_RespReason, "%s", http_Status2Reason(status, NULL));
+	VSLbs(req->vsl, SLT_RespReason,
+	      TOSTRAND(http_Status2Reason(status, NULL)));
 
 	if (status >= 400)
 		req->err_code = status;
diff --git a/tools/coccinelle/vslb_single_string.cocci b/tools/coccinelle/vslb_single_string.cocci
new file mode 100644
index 000000000..6e97d6490
--- /dev/null
+++ b/tools/coccinelle/vslb_single_string.cocci
@@ -0,0 +1,10 @@
+/*
+ * This patch avoids printf formatting with VSLb
+ */
+
+@@
+expression vsl, tag, str;
+@@
+
+- VSLb(vsl, tag, "%s", str)
++ VSLbs(vsl, tag, TOSTRAND(str))
diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c
index 091ad3048..d34d1f227 100644
--- a/vmod/vmod_debug.c
+++ b/vmod/vmod_debug.c
@@ -813,7 +813,8 @@ xyzzy_sethdr(VRT_CTX, VCL_HEADER hdr, VCL_STRANDS s)
 	} else {
 		b = VRT_StrandsWS(hp->ws, hdr->what + 1, s);
 		if (b == NULL) {
-			VSLb(ctx->vsl, SLT_LostHeader, "%s", hdr->what + 1);
+			VSLbs(ctx->vsl, SLT_LostHeader,
+			    TOSTRAND(hdr->what + 1));
 		} else {
 			if (*b != '\0')
 				AN(WS_Allocated(hp->ws, b, strlen(b) + 1));
diff --git a/vmod/vmod_debug_acl.c b/vmod/vmod_debug_acl.c
index 385565891..30a35df2e 100644
--- a/vmod/vmod_debug_acl.c
+++ b/vmod/vmod_debug_acl.c
@@ -200,7 +200,7 @@ xyzzy_sweep_acl(VRT_CTX, VCL_ACL acl, VCL_IP ip0, VCL_IP ip1, VCL_INT step)
 		VSB_putc(vsb, "-X"[i]);
 		if ((j & 0x3f) == 0x3f) {
 			AZ(VSB_finish(vsb));
-			VSLb(ctx->vsl, SLT_Debug, "%s", VSB_data(vsb));
+			VSLbs(ctx->vsl, SLT_Debug, TOSTRAND(VSB_data(vsb)));
 			sz =VSB_len(vsb);
 			assert (sz > 0);
 			VSHA256_Update(vsha, VSB_data(vsb), sz);
@@ -211,7 +211,7 @@ xyzzy_sweep_acl(VRT_CTX, VCL_ACL acl, VCL_IP ip0, VCL_IP ip1, VCL_INT step)
 	}
 	if (VSB_len(vsb)) {
 		AZ(VSB_finish(vsb));
-		VSLb(ctx->vsl, SLT_Debug, "%s", VSB_data(vsb));
+		VSLbs(ctx->vsl, SLT_Debug, TOSTRAND(VSB_data(vsb)));
 		sz =VSB_len(vsb);
 		assert (sz > 0);
 		VSHA256_Update(vsha, VSB_data(vsb), sz);


More information about the varnish-commit mailing list