Commit 88348095 authored by Emmanuel Hocdet's avatar Emmanuel Hocdet Committed by Martin Blix Grydeland

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 505b7bd9

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 e74f9e87)
parent efaa633c
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment