[6.0] 255896748 vrt: Perform IP to STRING conversion on the stack

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jun 3 08:46:05 UTC 2024


commit 2558967480a41bff781369e7dad0c0fcc1237897
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jan 3 18:36:16 2022 +0100

    vrt: Perform IP to STRING conversion on the stack
    
    Performing the conversion on the stack could lead to a buffer too small
    to store the string representation of the IP address. There is no test
    case because the error handling is output to stderr.
    
    Refs #3765
    
    Conflicts:
            bin/varnishd/cache/cache_vrt.c

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 27c80fb5d..d52ad0bb5 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -597,21 +597,16 @@ VRT_r_now(VRT_CTX)
 VCL_STRING v_matchproto_()
 VRT_IP_string(VRT_CTX, VCL_IP ip)
 {
-	char *p;
-	unsigned len;
+	char buf[VTCP_ADDRBUFSIZE];
+	struct vsb vsb[1];
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	if (ip == NULL)
 		return (NULL);
-	len = WS_ReserveAll(ctx->ws);
-	if (len == 0) {
-		WS_Release(ctx->ws, 0);
-		return (NULL);
-	}
-	p = ctx->ws->f;
-	VTCP_name(ip, p, len, NULL, 0);
-	WS_Release(ctx->ws, strlen(p) + 1);
-	return (p);
+	VTCP_name(ip, buf, sizeof buf, NULL, 0);
+	WS_VSB_new(vsb, ctx->ws);
+	VSB_cat(vsb, buf);
+	return (WS_VSB_finish(vsb, ctx->ws, NULL));
 }
 
 VCL_STRING v_matchproto_()


More information about the varnish-commit mailing list