[6.2] 33b8240b5 Simplify WS allocation in tlv_string

Martin Blix Grydeland martin at varnish-software.com
Tue Feb 4 10:03:08 UTC 2020


commit 33b8240b55156c303856868b822f054c6d86147c
Author: Emmanuel Hocdet <manu at gandi.net>
Date:   Thu Nov 14 11:14:07 2019 +0100

    Simplify WS allocation in tlv_string
    
    Patch by @ehocdet, commit message edited by @nigoroll:
    
    The root cause of #3131 was misdiagnosed to the extent that, while this
    change had prevented it, the root cause was a bug in WS_ReserveSize()
    fixed in 505b7bd9643006fa8e3977f920564ce12a2b24a2
    
    The previous tlv_string() code was correct except for the
    fact that error handling should have checked for WS_ReserveSize(ctx->ws,
    len+1) <= len (also spotted by @ehocdet).
    
    Someone had mentioned at some point that we would not want to VRT_fail(),
    but I think this must have been related to the proxy transport code, not
    the proxy vmod.
    
    Ref varnishcache/varnish-cache#3131
    
    (cherry picked from commit e74f9e871bc0eab014b7dd359d6ae83153c3ee37)

diff --git a/lib/libvmod_proxy/vmod_proxy.c b/lib/libvmod_proxy/vmod_proxy.c
index 58f2db295..222de9c53 100644
--- a/lib/libvmod_proxy/vmod_proxy.c
+++ b/lib/libvmod_proxy/vmod_proxy.c
@@ -105,12 +105,13 @@ tlv_string(VRT_CTX, int tlv)
 
 	if (VPX_tlv(ctx->req, tlv, (void **)&dst, &len))
 		return (NULL);
-	if (!WS_ReserveSize(ctx->ws, len+1))
+	d = WS_Alloc(ctx->ws, len+1);
+	if (d == NULL) {
+		VRT_fail(ctx, "proxy.TLV: out of workspace");
 		return (NULL);
-	d = ctx->ws->f;
+	}
 	memcpy(d, dst, len);
 	d[len] = '\0';
-	WS_Release(ctx->ws, len+1);
 	return (d);
 }
 


More information about the varnish-commit mailing list