From nils.goroll at uplex.de Mon Oct 7 15:36:08 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 7 Oct 2024 15:36:08 +0000 (UTC) Subject: [master] 9c3471692 vmod_debug: add debug.chksha256 / debug.chkcrc32 VDP to check body integrity Message-ID: <20241007153608.436BEA4E0A@lists.varnish-cache.org> commit 9c3471692d10ad328b0184155d24d051713053f1 Author: Nils Goroll Date: Mon Sep 30 10:18:20 2024 +0200 vmod_debug: add debug.chksha256 / debug.chkcrc32 VDP to check body integrity ... from within varnish, which does not allow to check for issues in the transport, but is useful for validating storage and any previous VDPs in the filter list. crc32 has been added as an option with higher performance, because the algorithm already exists in-tree. diff --git a/bin/varnishtest/tests/m00059.vtc b/bin/varnishtest/tests/m00059.vtc new file mode 100644 index 000000000..596bf87c6 --- /dev/null +++ b/bin/varnishtest/tests/m00059.vtc @@ -0,0 +1,81 @@ +varnishtest "VMOD debug.chksha256" + +server s1 { + rxreq + expect req.url == "/ok" + txresp \ + -hdr "sha256: 9cbca99698fee7cefd93bc6db1c53226fdecae730197fd793a54e170a30af045" \ + -hdr "crc32: 3177021206" \ + -hdr "Transfer-Encoding: chunked" -nolen + chunked "Ponto Facto, " + delay 1 + chunked "Caesar Transit!" + chunkedlen 0 + + rxreq + expect req.url == "/wrong" + txresp \ + -hdr "sha256: 9cbca99698fee7cefd93bc6db1c53226fdecae730197fd793a54e170a30af045" \ + -hdr "crc32: 3177021206" \ + -body "" +} -start + +varnish v1 \ + -arg "-p feature=+no_coredump" \ + -vcl+backend { + import debug; + import blob; + import std; + + sub vcl_deliver { + if (req.http.panic) { + debug.chksha256(blob.decode(HEX, + encoded=resp.http.sha256), panic); + debug.chkcrc32(std.integer(resp.http.crc32), panic); + } else { + debug.chksha256(blob.decode(HEX, + encoded=resp.http.sha256), log); + debug.chkcrc32(std.integer(resp.http.crc32), log); + } + set resp.filters += " debug.chksha256 debug.chkcrc32"; + } +} -start + +logexpect l1 -v v1 -g vxid -q "vxid == 1001" { + fail add * Debug "checksum mismatch" + expect * 1001 Begin + expect * = End + fail clear +} -start + +logexpect l2 -v v1 -g vxid -q "vxid == 1003" { + fail add * End + expect * 1003 Begin + expect * = Debug "^sha256 checksum mismatch" + expect 0 = Debug "^got: 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + expect 0 = Debug "^exp: 0x9cbca99698fee7cefd93bc6db1c53226fdecae730197fd793a54e170a30af045" + fail clear +} -start + +client c1 { + txreq -url "/ok" + rxresp + txreq -url "/wrong" + rxresp +} -run + +varnish v1 -vsl_catchup + +logexpect l1 -wait +logexpect l2 -wait + +client c1 { + txreq -url "/wrong" -hdr "panic: yes" + rxresp +} -run + +delay 3 + +varnish v1 -cliexpect "body checksum" "panic.show" +varnish v1 -cliok "panic.clear" +varnish v1 -expectexit 0x40 diff --git a/vmod/Makefile.am b/vmod/Makefile.am index ad3d4b95a..1d2df6317 100644 --- a/vmod/Makefile.am +++ b/vmod/Makefile.am @@ -45,6 +45,7 @@ include $(srcdir)/automake_boilerplate_vtc.am VSC_SRC = VSC_debug.vsc libvmod_debug_la_SOURCES += $(VSC_SRC) +libvmod_debug_la_CFLAGS += -I$(top_srcdir)/lib/libvgz BUILT_SOURCES = $(VSC_GEN) diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c index 33c1bf45e..1ced99c23 100644 --- a/vmod/vmod_debug.c +++ b/vmod/vmod_debug.c @@ -40,6 +40,8 @@ #include "cache/cache_filter.h" #include "vsa.h" +#include "vgz.h" +#include "vsha256.h" #include "vss.h" #include "vtcp.h" #include "vtim.h" @@ -362,6 +364,292 @@ static const struct vdp xyzzy_vdp_slow = { .bytes = xyzzy_vdp_slow_bytes }; +/* + * checksum VDP: + * test that the stream of bytes has a certain checksum and either log + * or panic + * + * The sha256 and crc32 variants are basically identical, but the amount of + * code does not justify generalizing. (slink) + */ + +enum vdp_chk_mode_e { + VDP_CHK_INVAL = 0, + VDP_CHK_LOG, + VDP_CHK_PANIC, + VDP_CHK_PANIC_UNLESS_ERROR +}; + +struct vdp_chksha256_cfg_s { + unsigned magic; +#define VDP_CHKSHA256_CFG_MAGIC 0x624f5b32 + enum vdp_chk_mode_e mode; + unsigned char expected[VSHA256_DIGEST_LENGTH]; +}; + +struct vdp_chkcrc32_cfg_s { + unsigned magic; +#define VDP_CHKCRC32_CFG_MAGIC 0x5a7a835c + enum vdp_chk_mode_e mode; + uint32_t expected; +}; + +struct vdp_chksha256_s { + unsigned magic; +#define VDP_CHKSHA256_MAGIC 0x6856e913 + unsigned called; + size_t bytes; + struct VSHA256Context cx[1]; + struct vdp_chksha256_cfg_s *cfg; +}; + +struct vdp_chkcrc32_s { + unsigned magic; +#define VDP_CHKCRC32_MAGIC 0x15c03d3c + unsigned called; + size_t bytes; + uint32_t crc; + struct vdp_chkcrc32_cfg_s *cfg; +}; + +; + +const void * const chksha256_priv_id = &chksha256_priv_id; +const void * const chkcrc32_priv_id = &chkcrc32_priv_id; + +static int v_matchproto_(vdp_init_f) +xyzzy_chksha256_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct vdp_chksha256_s *vdps; + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKSHA256_MAGIC); + if (vdps == NULL) + return (-1); + VSHA256_Init(vdps->cx); + + p = VRT_priv_task_get(ctx, chksha256_priv_id); + if (p == NULL) + return (-1); + + assert(p->len == sizeof(struct vdp_chksha256_cfg_s)); + CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKSHA256_CFG_MAGIC); + *priv = vdps; + + return (0); +} + +static int v_matchproto_(vdp_init_f) +xyzzy_chkcrc32_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct vdp_chkcrc32_s *vdps; + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKCRC32_MAGIC); + if (vdps == NULL) + return (-1); + vdps->crc = crc32(0L, Z_NULL, 0); + + p = VRT_priv_task_get(ctx, chkcrc32_priv_id); + if (p == NULL) + return (-1); + + assert(p->len == sizeof(struct vdp_chkcrc32_cfg_s)); + CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKCRC32_CFG_MAGIC); + *priv = vdps; + + return (0); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_chksha256_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + struct vdp_chksha256_s *vdps; + + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); + VSHA256_Update(vdps->cx, ptr, len); + vdps->called++; + vdps->bytes += len; + return (VDP_bytes(vdc, act, ptr, len)); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_chkcrc32_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + struct vdp_chkcrc32_s *vdps; + + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); + if (len > 0) + vdps->crc = crc32(vdps->crc, ptr, len); + vdps->called++; + vdps->bytes += len; + return (VDP_bytes(vdc, act, ptr, len)); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) +{ + unsigned char digest[VSHA256_DIGEST_LENGTH]; + enum vdp_chk_mode_e mode; + struct vdp_chksha256_s *vdps; + struct vsb *vsb; + int r; + + (void) vdc; + AN(priv); + if (*priv == NULL) + return (0); + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); + *priv = NULL; + + VSHA256_Final(digest, vdps->cx); + r = memcmp(digest, vdps->cfg->expected, sizeof digest); + if (r == 0) + return (0); + + mode = vdps->cfg->mode; + if (mode == VDP_CHK_PANIC_UNLESS_ERROR) + mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; + + if (mode == VDP_CHK_LOG) { + VSLb(vdc->vsl, SLT_Debug, "sha256 checksum mismatch"); + + vsb = VSB_new_auto(); + VSB_quote(vsb, digest, sizeof digest, VSB_QUOTE_HEX); + AZ(VSB_finish(vsb)); + VSLb(vdc->vsl, SLT_Debug, "got: %s", VSB_data(vsb)); + + VSB_clear(vsb); + VSB_quote(vsb, vdps->cfg->expected, sizeof digest, VSB_QUOTE_HEX); + AZ(VSB_finish(vsb)); + VSLb(vdc->vsl, SLT_Debug, "exp: %s", VSB_data(vsb)); + VSB_destroy(&vsb); + } + else if (mode == VDP_CHK_PANIC) + WRONG("body checksum"); + else + WRONG("mode"); + + return (0); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_chkcrc32_fini(struct vdp_ctx *vdc, void **priv) +{ + enum vdp_chk_mode_e mode; + struct vdp_chkcrc32_s *vdps; + + (void) vdc; + AN(priv); + if (*priv == NULL) + return (0); + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); + *priv = NULL; + + if (vdps->crc == vdps->cfg->expected) + return (0); + + mode = vdps->cfg->mode; + if (mode == VDP_CHK_PANIC_UNLESS_ERROR) + mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; + + if (mode == VDP_CHK_LOG) { + VSLb(vdc->vsl, SLT_Debug, "crc32 checksum mismatch"); + VSLb(vdc->vsl, SLT_Debug, "got: %08x", vdps->crc); + VSLb(vdc->vsl, SLT_Debug, "exp: %08x", vdps->cfg->expected); + } + else if (mode == VDP_CHK_PANIC) + WRONG("body checksum"); + else + WRONG("mode"); + + return (0); +} + +static const struct vdp xyzzy_vdp_chksha256 = { + .name = "debug.chksha256", + .init = xyzzy_chksha256_init, + .bytes = xyzzy_chksha256_bytes, + .fini = xyzzy_chksha256_fini, +}; + +static const struct vdp xyzzy_vdp_chkcrc32 = { + .name = "debug.chkcrc32", + .init = xyzzy_chkcrc32_init, + .bytes = xyzzy_chkcrc32_bytes, + .fini = xyzzy_chkcrc32_fini, +}; + +#define chkcfg(ws, cfg, magic, id, mode_e) do { \ + struct vmod_priv *p = VRT_priv_task(ctx, id); \ + \ + XXXAN(p); \ + if (p->priv == NULL) { \ + p->priv = WS_Alloc(ws, sizeof *cfg); \ + p->len = sizeof *cfg; \ + } \ + cfg = p->priv; \ + INIT_OBJ(cfg, magic); \ + if (mode_e == VENUM(log)) \ + cfg->mode = VDP_CHK_LOG; \ + else if (mode_e == VENUM(panic)) \ + cfg->mode = VDP_CHK_PANIC; \ + else if (mode_e == VENUM(panic_unless_error)) \ + cfg->mode = VDP_CHK_PANIC_UNLESS_ERROR; \ + else \ + WRONG("mode_e"); \ +} while(0) + +VCL_VOID v_matchproto_(td_xyzzy_debug_chksha256) +xyzzy_chksha256(VRT_CTX, VCL_BLOB blob, VCL_ENUM mode_e) +{ + struct vdp_chksha256_cfg_s *cfg; + size_t l; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + AN(blob); + XXXAN(blob->blob); + XXXAN(blob->len); + + chkcfg(ctx->ws, cfg, VDP_CHKSHA256_CFG_MAGIC, chksha256_priv_id, mode_e); + + l = blob->len; + if (l > sizeof cfg->expected) + l = sizeof cfg->expected; + memcpy(cfg->expected, blob->blob, l); + +} + +VCL_VOID v_matchproto_(td_xyzzy_debug_chkcrc32) +xyzzy_chkcrc32(VRT_CTX, VCL_INT expected, VCL_ENUM mode_e) +{ + struct vdp_chkcrc32_cfg_s *cfg; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + chkcfg(ctx->ws, cfg, VDP_CHKCRC32_CFG_MAGIC, chkcrc32_priv_id, mode_e); + + if (expected < 0) + expected = 0; + cfg->expected = (uintmax_t)expected % UINT32_MAX; +} + /**********************************************************************/ VCL_STRING v_matchproto_(td_debug_author) @@ -634,6 +922,8 @@ event_load(VRT_CTX, struct vmod_priv *priv) AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_pedantic)); AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chunked)); AZ(VRT_AddFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chksha256)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chkcrc32)); return (0); } @@ -799,6 +1089,8 @@ event_discard(VRT_CTX, void *priv) VRT_RemoveFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13); VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_pedantic); VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chunked); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chksha256); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chkcrc32); if (--loads) return (0); diff --git a/vmod/vmod_debug.vcc b/vmod/vmod_debug.vcc index 0299c19cb..e3f80b0cc 100644 --- a/vmod/vmod_debug.vcc +++ b/vmod/vmod_debug.vcc @@ -410,6 +410,36 @@ resolved sockets are retuned in a comma delimited string. If fail_port is specified, the resolution callback will fail for that port, and the reason will be appended to the return value. +$Function VOID chksha256(BLOB expected, ENUM {log, panic, panic_unless_error} mode) + +Configure the expected sha256 checksum and failure mode for the debug.chksha256 +VDP. This function does not push the VDP. + +The *expected* blob should be 32 bytes in length. If not, it will either be +truncated or padded with zeros. + +With *mode* ``log``, the VDP emits ``Debug`` VSL like the following for a +checksum mismatch:: + + Debug c checksum mismatch + Debug c got: 0xe3b0c44298fc1c149afbf4c8996fb924... + Debug c exp: 0x9cbca99698fee7cefd93bc6db1c53226... + +With *mode* ``panic``, the VDP triggers a ``WRONG("body checksum")`` for a +mismatch. The ``panic_unless_error`` *mode* does so only if the filter chain was +otherwise closed without error. This is useful, for example, to not trigger a +panic when the client closes the connection. + +$Function VOID chkcrc32(INT expected, ENUM {log, panic, panic_unless_error} mode) + +Configure the expected crc32 checksum and failure mode for the debug.chkcrc32 +VDP. This function does not push the VDP. + +*expected* needs to be in the range ``0 .. UINT32_MAX``. A negative value will +be hanged to zero. Any larger value will be taken modulo UINT32_MAX. + +The *mode* argument behaves as for `debug.chksha256()`_. + DEPRECATED ========== From nils.goroll at uplex.de Mon Oct 7 16:03:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 7 Oct 2024 16:03:05 +0000 (UTC) Subject: [master] 5cb857197 vmod_debug: split filter sources from rest of the code Message-ID: <20241007160305.8FB82A60AB@lists.varnish-cache.org> commit 5cb857197d471b4ccb175978b269441e25316dfc Author: Nils Goroll Date: Mon Oct 7 17:51:19 2024 +0200 vmod_debug: split filter sources from rest of the code and flexelint diff --git a/vmod/automake_boilerplate_debug.am b/vmod/automake_boilerplate_debug.am index abda2454e..f2f2e36ad 100644 --- a/vmod/automake_boilerplate_debug.am +++ b/vmod/automake_boilerplate_debug.am @@ -10,6 +10,7 @@ libvmod_debug_la_SOURCES = \ vmod_debug.c \ vmod_debug_acl.c \ vmod_debug_dyn.c \ + vmod_debug_filters.c \ vmod_debug_obj.c libvmod_debug_la_CFLAGS = diff --git a/vmod/flint.sh b/vmod/flint.sh index 19053bcae..7ad9deeb0 100644 --- a/vmod/flint.sh +++ b/vmod/flint.sh @@ -10,6 +10,6 @@ for vmod in vmod_*.vcc ; do echo "${vmod}" echo "=====================" vmod="${vmod#vmod_}" - FLOPS="-I../bin/varnishd vcc_${vmod}_if.c vmod_${vmod}*.c" \ + FLOPS="-I../bin/varnishd -I../lib/libvgz vcc_${vmod}_if.c vmod_${vmod}*.c" \ ../tools/flint_skel.sh done diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c index 1ced99c23..259497f8d 100644 --- a/vmod/vmod_debug.c +++ b/vmod/vmod_debug.c @@ -40,14 +40,14 @@ #include "cache/cache_filter.h" #include "vsa.h" -#include "vgz.h" -#include "vsha256.h" #include "vss.h" #include "vtcp.h" #include "vtim.h" #include "vcc_debug_if.h" #include "VSC_debug.h" +#include "vmod_debug.h" + struct priv_vcl { unsigned magic; #define PRIV_VCL_MAGIC 0x8E62FA9D @@ -74,584 +74,6 @@ extern void mylog(struct vsl_log *vsl, enum VSL_tag_e tag, /**********************************************************************/ -static enum vfp_status v_matchproto_(vfp_pull_f) -xyzzy_vfp_rot13_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, - ssize_t *lp) -{ - enum vfp_status vp; - char *q; - ssize_t l; - - (void)vfe; - vp = VFP_Suck(vc, p, lp); - if (vp == VFP_ERROR) - return (vp); - q = p; - for (l = 0; l < *lp; l++, q++) { - if (*q >= 'A' && *q <= 'Z') - *q = (((*q - 'A') + 13) % 26) + 'A'; - if (*q >= 'a' && *q <= 'z') - *q = (((*q - 'a') + 13) % 26) + 'a'; - } - return (vp); -} - -static const struct vfp xyzzy_vfp_rot13 = { - .name = "rot13", - .pull = xyzzy_vfp_rot13_pull, -}; - -/**********************************************************************/ - -// deliberately fragmenting the stream to make testing more interesting -#define ROT13_BUFSZ 8 - -static int v_matchproto_(vdp_init_f) -xyzzy_vdp_rot13_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) -{ - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); - CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); - AN(vdc->clen); - - AN(priv); - - *priv = malloc(ROT13_BUFSZ); - if (*priv == NULL) - return (-1); - - return (0); -} - -static int v_matchproto_(vdp_bytes_f) -xyzzy_vdp_rot13_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, - const void *ptr, ssize_t len) -{ - char *q; - const char *pp; - int i, j, retval = 0; - - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - AN(priv); - AN(*priv); - if (len <= 0) - return (VDP_bytes(vdc, act, ptr, len)); - AN(ptr); - if (act != VDP_END) - act = VDP_FLUSH; - q = *priv; - pp = ptr; - - for (i = 0, j = 0; j < len; i++, j++) { - if (pp[j] >= 'A' && pp[j] <= 'Z') - q[i] = (((pp[j] - 'A') + 13) % 26) + 'A'; - else if (pp[j] >= 'a' && pp[j] <= 'z') - q[i] = (((pp[j] - 'a') + 13) % 26) + 'a'; - else - q[i] = pp[j]; - if (i == ROT13_BUFSZ - 1 && j < len - 1) { - retval = VDP_bytes(vdc, VDP_FLUSH, q, ROT13_BUFSZ); - if (retval != 0) - return (retval); - i = -1; - } - } - if (i >= 0) - retval = VDP_bytes(vdc, act, q, i); - return (retval); -} - -static int v_matchproto_(vdp_fini_f) -xyzzy_vdp_rot13_fini(struct vdp_ctx *vdc, void **priv) -{ - (void)vdc; - AN(priv); - free(*priv); - *priv = NULL; - return (0); -} - -static const struct vdp xyzzy_vdp_rot13 = { - .name = "rot13", - .init = xyzzy_vdp_rot13_init, - .bytes = xyzzy_vdp_rot13_bytes, - .fini = xyzzy_vdp_rot13_fini, -}; - -/********************************************************************** - * vdp debug_chunked: force http1 chunked encoding by removing the - * Content-Length header - * - * this happens in a VDP because cnt_transmit() runs after VCL and - * restores it - */ - -static int v_matchproto_(vdp_init_f) -xyzzy_vdp_chunked_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) -{ - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); - CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); - AN(vdc->clen); - AN(priv); - - http_Unset(vdc->hp, H_Content_Length); - *vdc->clen = -1; - - return (1); -} - -static const struct vdp xyzzy_vdp_chunked = { - .name = "debug.chunked", - .init = xyzzy_vdp_chunked_init, -}; - -/********************************************************************** - * pedantic tests of the VDP API: - * - assert that we see a VDP_END - * - assert that _fini gets called before the task ends - * - * note: - * we could lookup our own vdpe in _fini and check for vdpe->end == VDP_END - * yet that would cross the API - */ - -enum vdp_state_e { - VDPS_NULL = 0, - VDPS_INIT, // _init called - VDPS_BYTES, // _bytes called act != VDP_END - VDPS_END, // _bytes called act == VDP_END - VDPS_FINI // _fini called -}; - -struct vdp_state_s { - unsigned magic; -#define VDP_STATE_MAGIC 0x57c8d309 - enum vdp_state_e state; -}; - -static void v_matchproto_(vmod_priv_fini_f) -priv_pedantic_fini(VRT_CTX, void *priv) -{ - struct vdp_state_s *vdps; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CAST_OBJ_NOTNULL(vdps, priv, VDP_STATE_MAGIC); - - assert(vdps->state == VDPS_FINI); -} - -static const struct vmod_priv_methods priv_pedantic_methods[1] = {{ - .magic = VMOD_PRIV_METHODS_MAGIC, - .type = "debug_vdp_pedantic", - .fini = priv_pedantic_fini -}}; - -static int v_matchproto_(vdp_init_f) -xyzzy_pedantic_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) -{ - struct vdp_state_s *vdps; - struct vmod_priv *p; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); - CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); - AN(vdc->clen); - AN(priv); - - WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_STATE_MAGIC); - if (vdps == NULL) - return (-1); - assert(vdps->state == VDPS_NULL); - - p = VRT_priv_task(ctx, (void *)vdc); - if (p == NULL) - return (-1); - p->priv = vdps; - p->methods = priv_pedantic_methods; - - *priv = vdps; - - vdps->state = VDPS_INIT; - - return (0); -} - -static int v_matchproto_(vdp_bytes_f) -xyzzy_pedantic_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, - const void *ptr, ssize_t len) -{ - struct vdp_state_s *vdps; - - CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); - assert(vdps->state >= VDPS_INIT); - assert(vdps->state < VDPS_END); - - if (act == VDP_END) - vdps->state = VDPS_END; - else - vdps->state = VDPS_BYTES; - - return (VDP_bytes(vdc, act, ptr, len)); -} - -static int v_matchproto_(vdp_fini_f) -xyzzy_pedantic_fini(struct vdp_ctx *vdc, void **priv) -{ - struct vdp_state_s *vdps; - - (void) vdc; - AN(priv); - if (*priv == NULL) - return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); - assert(vdps->state == VDPS_INIT || vdps->state == VDPS_END); - vdps->state = VDPS_FINI; - - *priv = NULL; - return (0); -} - -static const struct vdp xyzzy_vdp_pedantic = { - .name = "debug.pedantic", - .init = xyzzy_pedantic_init, - .bytes = xyzzy_pedantic_bytes, - .fini = xyzzy_pedantic_fini, -}; - -/********************************************************************** - * - * this trivial copy/paste/edit filter (of rot13) was specifically made for - * someone who added a DBG_SLOW_BEREQ debug flag. It should actually be turned - * in a proper "bandwidth control" filter, but that exceeds an evening's work, - * so it's kept for later - */ - -static enum vfp_status v_matchproto_(vfp_pull_f) -xyzzy_vfp_slow_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, - ssize_t *lp) -{ - - (void)vfe; - VTIM_sleep(1.0); - return (VFP_Suck(vc, p, lp)); -} - -static const struct vfp xyzzy_vfp_slow = { - .name = "debug.slow", - .pull = xyzzy_vfp_slow_pull, -}; - -/**********************************************************************/ - -static int v_matchproto_(vdp_bytes_f) -xyzzy_vdp_slow_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, - const void *ptr, ssize_t len) -{ - - (void)priv; - VTIM_sleep(1.0); - return (VDP_bytes(vdc, act, ptr, len)); -} - -static const struct vdp xyzzy_vdp_slow = { - .name = "debug.slow", - .bytes = xyzzy_vdp_slow_bytes -}; - -/* - * checksum VDP: - * test that the stream of bytes has a certain checksum and either log - * or panic - * - * The sha256 and crc32 variants are basically identical, but the amount of - * code does not justify generalizing. (slink) - */ - -enum vdp_chk_mode_e { - VDP_CHK_INVAL = 0, - VDP_CHK_LOG, - VDP_CHK_PANIC, - VDP_CHK_PANIC_UNLESS_ERROR -}; - -struct vdp_chksha256_cfg_s { - unsigned magic; -#define VDP_CHKSHA256_CFG_MAGIC 0x624f5b32 - enum vdp_chk_mode_e mode; - unsigned char expected[VSHA256_DIGEST_LENGTH]; -}; - -struct vdp_chkcrc32_cfg_s { - unsigned magic; -#define VDP_CHKCRC32_CFG_MAGIC 0x5a7a835c - enum vdp_chk_mode_e mode; - uint32_t expected; -}; - -struct vdp_chksha256_s { - unsigned magic; -#define VDP_CHKSHA256_MAGIC 0x6856e913 - unsigned called; - size_t bytes; - struct VSHA256Context cx[1]; - struct vdp_chksha256_cfg_s *cfg; -}; - -struct vdp_chkcrc32_s { - unsigned magic; -#define VDP_CHKCRC32_MAGIC 0x15c03d3c - unsigned called; - size_t bytes; - uint32_t crc; - struct vdp_chkcrc32_cfg_s *cfg; -}; - -; - -const void * const chksha256_priv_id = &chksha256_priv_id; -const void * const chkcrc32_priv_id = &chkcrc32_priv_id; - -static int v_matchproto_(vdp_init_f) -xyzzy_chksha256_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) -{ - struct vdp_chksha256_s *vdps; - struct vmod_priv *p; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); - CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); - AN(vdc->clen); - AN(priv); - - WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKSHA256_MAGIC); - if (vdps == NULL) - return (-1); - VSHA256_Init(vdps->cx); - - p = VRT_priv_task_get(ctx, chksha256_priv_id); - if (p == NULL) - return (-1); - - assert(p->len == sizeof(struct vdp_chksha256_cfg_s)); - CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKSHA256_CFG_MAGIC); - *priv = vdps; - - return (0); -} - -static int v_matchproto_(vdp_init_f) -xyzzy_chkcrc32_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) -{ - struct vdp_chkcrc32_s *vdps; - struct vmod_priv *p; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); - CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); - AN(vdc->clen); - AN(priv); - - WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKCRC32_MAGIC); - if (vdps == NULL) - return (-1); - vdps->crc = crc32(0L, Z_NULL, 0); - - p = VRT_priv_task_get(ctx, chkcrc32_priv_id); - if (p == NULL) - return (-1); - - assert(p->len == sizeof(struct vdp_chkcrc32_cfg_s)); - CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKCRC32_CFG_MAGIC); - *priv = vdps; - - return (0); -} - -static int v_matchproto_(vdp_bytes_f) -xyzzy_chksha256_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, - const void *ptr, ssize_t len) -{ - struct vdp_chksha256_s *vdps; - - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); - VSHA256_Update(vdps->cx, ptr, len); - vdps->called++; - vdps->bytes += len; - return (VDP_bytes(vdc, act, ptr, len)); -} - -static int v_matchproto_(vdp_bytes_f) -xyzzy_chkcrc32_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, - const void *ptr, ssize_t len) -{ - struct vdp_chkcrc32_s *vdps; - - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); - if (len > 0) - vdps->crc = crc32(vdps->crc, ptr, len); - vdps->called++; - vdps->bytes += len; - return (VDP_bytes(vdc, act, ptr, len)); -} - -static int v_matchproto_(vdp_fini_f) -xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) -{ - unsigned char digest[VSHA256_DIGEST_LENGTH]; - enum vdp_chk_mode_e mode; - struct vdp_chksha256_s *vdps; - struct vsb *vsb; - int r; - - (void) vdc; - AN(priv); - if (*priv == NULL) - return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); - *priv = NULL; - - VSHA256_Final(digest, vdps->cx); - r = memcmp(digest, vdps->cfg->expected, sizeof digest); - if (r == 0) - return (0); - - mode = vdps->cfg->mode; - if (mode == VDP_CHK_PANIC_UNLESS_ERROR) - mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; - - if (mode == VDP_CHK_LOG) { - VSLb(vdc->vsl, SLT_Debug, "sha256 checksum mismatch"); - - vsb = VSB_new_auto(); - VSB_quote(vsb, digest, sizeof digest, VSB_QUOTE_HEX); - AZ(VSB_finish(vsb)); - VSLb(vdc->vsl, SLT_Debug, "got: %s", VSB_data(vsb)); - - VSB_clear(vsb); - VSB_quote(vsb, vdps->cfg->expected, sizeof digest, VSB_QUOTE_HEX); - AZ(VSB_finish(vsb)); - VSLb(vdc->vsl, SLT_Debug, "exp: %s", VSB_data(vsb)); - VSB_destroy(&vsb); - } - else if (mode == VDP_CHK_PANIC) - WRONG("body checksum"); - else - WRONG("mode"); - - return (0); -} - -static int v_matchproto_(vdp_fini_f) -xyzzy_chkcrc32_fini(struct vdp_ctx *vdc, void **priv) -{ - enum vdp_chk_mode_e mode; - struct vdp_chkcrc32_s *vdps; - - (void) vdc; - AN(priv); - if (*priv == NULL) - return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); - *priv = NULL; - - if (vdps->crc == vdps->cfg->expected) - return (0); - - mode = vdps->cfg->mode; - if (mode == VDP_CHK_PANIC_UNLESS_ERROR) - mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; - - if (mode == VDP_CHK_LOG) { - VSLb(vdc->vsl, SLT_Debug, "crc32 checksum mismatch"); - VSLb(vdc->vsl, SLT_Debug, "got: %08x", vdps->crc); - VSLb(vdc->vsl, SLT_Debug, "exp: %08x", vdps->cfg->expected); - } - else if (mode == VDP_CHK_PANIC) - WRONG("body checksum"); - else - WRONG("mode"); - - return (0); -} - -static const struct vdp xyzzy_vdp_chksha256 = { - .name = "debug.chksha256", - .init = xyzzy_chksha256_init, - .bytes = xyzzy_chksha256_bytes, - .fini = xyzzy_chksha256_fini, -}; - -static const struct vdp xyzzy_vdp_chkcrc32 = { - .name = "debug.chkcrc32", - .init = xyzzy_chkcrc32_init, - .bytes = xyzzy_chkcrc32_bytes, - .fini = xyzzy_chkcrc32_fini, -}; - -#define chkcfg(ws, cfg, magic, id, mode_e) do { \ - struct vmod_priv *p = VRT_priv_task(ctx, id); \ - \ - XXXAN(p); \ - if (p->priv == NULL) { \ - p->priv = WS_Alloc(ws, sizeof *cfg); \ - p->len = sizeof *cfg; \ - } \ - cfg = p->priv; \ - INIT_OBJ(cfg, magic); \ - if (mode_e == VENUM(log)) \ - cfg->mode = VDP_CHK_LOG; \ - else if (mode_e == VENUM(panic)) \ - cfg->mode = VDP_CHK_PANIC; \ - else if (mode_e == VENUM(panic_unless_error)) \ - cfg->mode = VDP_CHK_PANIC_UNLESS_ERROR; \ - else \ - WRONG("mode_e"); \ -} while(0) - -VCL_VOID v_matchproto_(td_xyzzy_debug_chksha256) -xyzzy_chksha256(VRT_CTX, VCL_BLOB blob, VCL_ENUM mode_e) -{ - struct vdp_chksha256_cfg_s *cfg; - size_t l; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - AN(blob); - XXXAN(blob->blob); - XXXAN(blob->len); - - chkcfg(ctx->ws, cfg, VDP_CHKSHA256_CFG_MAGIC, chksha256_priv_id, mode_e); - - l = blob->len; - if (l > sizeof cfg->expected) - l = sizeof cfg->expected; - memcpy(cfg->expected, blob->blob, l); - -} - -VCL_VOID v_matchproto_(td_xyzzy_debug_chkcrc32) -xyzzy_chkcrc32(VRT_CTX, VCL_INT expected, VCL_ENUM mode_e) -{ - struct vdp_chkcrc32_cfg_s *cfg; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - - chkcfg(ctx->ws, cfg, VDP_CHKCRC32_CFG_MAGIC, chkcrc32_priv_id, mode_e); - - if (expected < 0) - expected = 0; - cfg->expected = (uintmax_t)expected % UINT32_MAX; -} - -/**********************************************************************/ - VCL_STRING v_matchproto_(td_debug_author) xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone) { @@ -783,15 +205,6 @@ xyzzy_test_priv_vcl(VRT_CTX, struct vmod_priv *priv) assert(!strncmp(priv_vcl->foo, t, l)); } -VCL_VOID v_matchproto_(td_debug_rot104) -xyzzy_rot104(VRT_CTX) -{ - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - // This should fail - AN(VRT_AddFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13)); -} - VCL_VOID v_matchproto_(td_debug_rot52) xyzzy_rot52(VRT_CTX, VCL_HTTP hp) { @@ -918,12 +331,7 @@ event_load(VRT_CTX, struct vmod_priv *priv) priv->priv = priv_vcl; priv->methods = priv_vcl_methods; - AZ(VRT_AddFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13)); - AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_pedantic)); - AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chunked)); - AZ(VRT_AddFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow)); - AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chksha256)); - AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chkcrc32)); + debug_add_filters(ctx); return (0); } @@ -1085,12 +493,7 @@ event_discard(VRT_CTX, void *priv) AZ(ctx->msg); - VRT_RemoveFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow); - VRT_RemoveFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13); - VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_pedantic); - VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chunked); - VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chksha256); - VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chkcrc32); + debug_remove_filters(ctx); if (--loads) return (0); diff --git a/vmod/vmod_debug.h b/vmod/vmod_debug.h new file mode 100644 index 000000000..05093be07 --- /dev/null +++ b/vmod/vmod_debug.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2012-2019 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * SPDX-License-Identifier: BSD-2-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* vmod_debug_filters.c */ +void +debug_add_filters(VRT_CTX); +void +debug_remove_filters(VRT_CTX); diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c new file mode 100644 index 000000000..dba6c4a68 --- /dev/null +++ b/vmod/vmod_debug_filters.c @@ -0,0 +1,655 @@ +/*- + * Copyright (c) 2012-2019 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * SPDX-License-Identifier: BSD-2-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "cache/cache_varnishd.h" +#include "cache/cache_filter.h" + +#include "vgz.h" +#include "vsha256.h" +#include "vtim.h" +#include "vcc_debug_if.h" + +#include "vmod_debug.h" + +/**********************************************************************/ + +static enum vfp_status v_matchproto_(vfp_pull_f) +xyzzy_vfp_rot13_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, + ssize_t *lp) +{ + enum vfp_status vp; + char *q; + ssize_t l; + + (void)vfe; + vp = VFP_Suck(vc, p, lp); + if (vp == VFP_ERROR) + return (vp); + q = p; + for (l = 0; l < *lp; l++, q++) { + if (*q >= 'A' && *q <= 'Z') + *q = (((*q - 'A') + 13) % 26) + 'A'; + if (*q >= 'a' && *q <= 'z') + *q = (((*q - 'a') + 13) % 26) + 'a'; + } + return (vp); +} + +static const struct vfp xyzzy_vfp_rot13 = { + .name = "rot13", + .pull = xyzzy_vfp_rot13_pull, +}; + +/**********************************************************************/ + +// deliberately fragmenting the stream to make testing more interesting +#define ROT13_BUFSZ 8 + +static int v_matchproto_(vdp_init_f) +xyzzy_vdp_rot13_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + + AN(priv); + + *priv = malloc(ROT13_BUFSZ); + if (*priv == NULL) + return (-1); + + return (0); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_vdp_rot13_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + char *q; + const char *pp; + int i, j, retval = 0; + + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + AN(priv); + AN(*priv); + if (len <= 0) + return (VDP_bytes(vdc, act, ptr, len)); + AN(ptr); + if (act != VDP_END) + act = VDP_FLUSH; + q = *priv; + pp = ptr; + + for (i = 0, j = 0; j < len; i++, j++) { + if (pp[j] >= 'A' && pp[j] <= 'Z') + q[i] = (((pp[j] - 'A') + 13) % 26) + 'A'; + else if (pp[j] >= 'a' && pp[j] <= 'z') + q[i] = (((pp[j] - 'a') + 13) % 26) + 'a'; + else + q[i] = pp[j]; + if (i == ROT13_BUFSZ - 1 && j < len - 1) { + retval = VDP_bytes(vdc, VDP_FLUSH, q, ROT13_BUFSZ); + if (retval != 0) + return (retval); + i = -1; + } + } + if (i >= 0) + retval = VDP_bytes(vdc, act, q, i); + return (retval); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_vdp_rot13_fini(struct vdp_ctx *vdc, void **priv) +{ + (void)vdc; + AN(priv); + free(*priv); + *priv = NULL; + return (0); +} + +static const struct vdp xyzzy_vdp_rot13 = { + .name = "rot13", + .init = xyzzy_vdp_rot13_init, + .bytes = xyzzy_vdp_rot13_bytes, + .fini = xyzzy_vdp_rot13_fini, +}; + +VCL_VOID v_matchproto_(td_debug_rot104) +xyzzy_rot104(VRT_CTX) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + // This should fail + AN(VRT_AddFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13)); +} + +/********************************************************************** + * vdp debug_chunked: force http1 chunked encoding by removing the + * Content-Length header + * + * this happens in a VDP because cnt_transmit() runs after VCL and + * restores it + */ + +static int v_matchproto_(vdp_init_f) +xyzzy_vdp_chunked_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + http_Unset(vdc->hp, H_Content_Length); + *vdc->clen = -1; + + return (1); +} + +static const struct vdp xyzzy_vdp_chunked = { + .name = "debug.chunked", + .init = xyzzy_vdp_chunked_init, +}; + +/********************************************************************** + * pedantic tests of the VDP API: + * - assert that we see a VDP_END + * - assert that _fini gets called before the task ends + * + * note: + * we could lookup our own vdpe in _fini and check for vdpe->end == VDP_END + * yet that would cross the API + */ + +enum vdp_state_e { + VDPS_NULL = 0, + VDPS_INIT, // _init called + VDPS_BYTES, // _bytes called act != VDP_END + VDPS_END, // _bytes called act == VDP_END + VDPS_FINI // _fini called +}; + +struct vdp_state_s { + unsigned magic; +#define VDP_STATE_MAGIC 0x57c8d309 + enum vdp_state_e state; +}; + +static void v_matchproto_(vmod_priv_fini_f) +priv_pedantic_fini(VRT_CTX, void *priv) +{ + struct vdp_state_s *vdps; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CAST_OBJ_NOTNULL(vdps, priv, VDP_STATE_MAGIC); + + assert(vdps->state == VDPS_FINI); +} + +static const struct vmod_priv_methods priv_pedantic_methods[1] = {{ + .magic = VMOD_PRIV_METHODS_MAGIC, + .type = "debug_vdp_pedantic", + .fini = priv_pedantic_fini +}}; + +static int v_matchproto_(vdp_init_f) +xyzzy_pedantic_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct vdp_state_s *vdps; + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_STATE_MAGIC); + if (vdps == NULL) + return (-1); + assert(vdps->state == VDPS_NULL); + + p = VRT_priv_task(ctx, (void *)vdc); + if (p == NULL) + return (-1); + p->priv = vdps; + p->methods = priv_pedantic_methods; + + *priv = vdps; + + vdps->state = VDPS_INIT; + + return (0); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_pedantic_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + struct vdp_state_s *vdps; + + CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); + assert(vdps->state >= VDPS_INIT); + assert(vdps->state < VDPS_END); + + if (act == VDP_END) + vdps->state = VDPS_END; + else + vdps->state = VDPS_BYTES; + + return (VDP_bytes(vdc, act, ptr, len)); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_pedantic_fini(struct vdp_ctx *vdc, void **priv) +{ + struct vdp_state_s *vdps; + + (void) vdc; + AN(priv); + if (*priv == NULL) + return (0); + CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); + assert(vdps->state == VDPS_INIT || vdps->state == VDPS_END); + vdps->state = VDPS_FINI; + + *priv = NULL; + return (0); +} + +static const struct vdp xyzzy_vdp_pedantic = { + .name = "debug.pedantic", + .init = xyzzy_pedantic_init, + .bytes = xyzzy_pedantic_bytes, + .fini = xyzzy_pedantic_fini, +}; + +/********************************************************************** + * + * this trivial copy/paste/edit filter (of rot13) was specifically made for + * someone who added a DBG_SLOW_BEREQ debug flag. It should actually be turned + * in a proper "bandwidth control" filter, but that exceeds an evening's work, + * so it's kept for later + */ + +static enum vfp_status v_matchproto_(vfp_pull_f) +xyzzy_vfp_slow_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, + ssize_t *lp) +{ + + (void)vfe; + VTIM_sleep(1.0); + return (VFP_Suck(vc, p, lp)); +} + +static const struct vfp xyzzy_vfp_slow = { + .name = "debug.slow", + .pull = xyzzy_vfp_slow_pull, +}; + +/**********************************************************************/ + +static int v_matchproto_(vdp_bytes_f) +xyzzy_vdp_slow_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + + (void)priv; + VTIM_sleep(1.0); + return (VDP_bytes(vdc, act, ptr, len)); +} + +static const struct vdp xyzzy_vdp_slow = { + .name = "debug.slow", + .bytes = xyzzy_vdp_slow_bytes +}; + +/* + * checksum VDP: + * test that the stream of bytes has a certain checksum and either log + * or panic + * + * The sha256 and crc32 variants are basically identical, but the amount of + * code does not justify generalizing. (slink) + */ + +enum vdp_chk_mode_e { + //lint -esym(749, vdp_chk_mode_e::VDP_CHK_INVAL) deliberately not referenced + VDP_CHK_INVAL = 0, + VDP_CHK_LOG, + VDP_CHK_PANIC, + VDP_CHK_PANIC_UNLESS_ERROR +}; + +struct vdp_chksha256_cfg_s { + unsigned magic; +#define VDP_CHKSHA256_CFG_MAGIC 0x624f5b32 + enum vdp_chk_mode_e mode; + unsigned char expected[VSHA256_DIGEST_LENGTH]; +}; + +struct vdp_chkcrc32_cfg_s { + unsigned magic; +#define VDP_CHKCRC32_CFG_MAGIC 0x5a7a835c + enum vdp_chk_mode_e mode; + uint32_t expected; +}; + +struct vdp_chksha256_s { + unsigned magic; +#define VDP_CHKSHA256_MAGIC 0x6856e913 + unsigned called; + size_t bytes; + struct VSHA256Context cx[1]; + struct vdp_chksha256_cfg_s *cfg; +}; + +struct vdp_chkcrc32_s { + unsigned magic; +#define VDP_CHKCRC32_MAGIC 0x15c03d3c + unsigned called; + size_t bytes; + uint32_t crc; + struct vdp_chkcrc32_cfg_s *cfg; +}; + +static const void * const chksha256_priv_id = &chksha256_priv_id; +static const void * const chkcrc32_priv_id = &chkcrc32_priv_id; + +static int v_matchproto_(vdp_init_f) +xyzzy_chksha256_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct vdp_chksha256_s *vdps; + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKSHA256_MAGIC); + if (vdps == NULL) + return (-1); + VSHA256_Init(vdps->cx); + + p = VRT_priv_task_get(ctx, chksha256_priv_id); + if (p == NULL) + return (-1); + + assert(p->len == sizeof(struct vdp_chksha256_cfg_s)); + CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKSHA256_CFG_MAGIC); + *priv = vdps; + + return (0); +} + +static int v_matchproto_(vdp_init_f) +xyzzy_chkcrc32_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct vdp_chkcrc32_s *vdps; + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + WS_TASK_ALLOC_OBJ(ctx, vdps, VDP_CHKCRC32_MAGIC); + if (vdps == NULL) + return (-1); + vdps->crc = crc32(0L, Z_NULL, 0); + + p = VRT_priv_task_get(ctx, chkcrc32_priv_id); + if (p == NULL) + return (-1); + + assert(p->len == sizeof(struct vdp_chkcrc32_cfg_s)); + CAST_OBJ_NOTNULL(vdps->cfg, p->priv, VDP_CHKCRC32_CFG_MAGIC); + *priv = vdps; + + return (0); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_chksha256_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + struct vdp_chksha256_s *vdps; + + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); + VSHA256_Update(vdps->cx, ptr, len); + vdps->called++; + vdps->bytes += len; + return (VDP_bytes(vdc, act, ptr, len)); +} + +static int v_matchproto_(vdp_bytes_f) +xyzzy_chkcrc32_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv, + const void *ptr, ssize_t len) +{ + struct vdp_chkcrc32_s *vdps; + + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); + if (len > 0) + vdps->crc = crc32(vdps->crc, ptr, len); + vdps->called++; + vdps->bytes += len; + return (VDP_bytes(vdc, act, ptr, len)); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) +{ + unsigned char digest[VSHA256_DIGEST_LENGTH]; + enum vdp_chk_mode_e mode; + struct vdp_chksha256_s *vdps; + struct vsb *vsb; + int r; + + (void) vdc; + AN(priv); + if (*priv == NULL) + return (0); + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); + *priv = NULL; + + VSHA256_Final(digest, vdps->cx); + r = memcmp(digest, vdps->cfg->expected, sizeof digest); + if (r == 0) + return (0); + + mode = vdps->cfg->mode; + if (mode == VDP_CHK_PANIC_UNLESS_ERROR) + mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; + + if (mode == VDP_CHK_LOG) { + VSLb(vdc->vsl, SLT_Debug, "sha256 checksum mismatch"); + + vsb = VSB_new_auto(); + VSB_quote(vsb, digest, sizeof digest, VSB_QUOTE_HEX); + AZ(VSB_finish(vsb)); + VSLb(vdc->vsl, SLT_Debug, "got: %s", VSB_data(vsb)); + + VSB_clear(vsb); + VSB_quote(vsb, vdps->cfg->expected, sizeof digest, VSB_QUOTE_HEX); + AZ(VSB_finish(vsb)); + VSLb(vdc->vsl, SLT_Debug, "exp: %s", VSB_data(vsb)); + VSB_destroy(&vsb); + } + else if (mode == VDP_CHK_PANIC) + WRONG("body checksum"); + else + WRONG("mode"); + + return (0); +} + +static int v_matchproto_(vdp_fini_f) +xyzzy_chkcrc32_fini(struct vdp_ctx *vdc, void **priv) +{ + enum vdp_chk_mode_e mode; + struct vdp_chkcrc32_s *vdps; + + (void) vdc; + AN(priv); + if (*priv == NULL) + return (0); + CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); + *priv = NULL; + + if (vdps->crc == vdps->cfg->expected) + return (0); + + mode = vdps->cfg->mode; + if (mode == VDP_CHK_PANIC_UNLESS_ERROR) + mode = (vdps->called == 0 || vdc->retval != 0) ? VDP_CHK_LOG : VDP_CHK_PANIC; + + if (mode == VDP_CHK_LOG) { + VSLb(vdc->vsl, SLT_Debug, "crc32 checksum mismatch"); + VSLb(vdc->vsl, SLT_Debug, "got: %08x", vdps->crc); + VSLb(vdc->vsl, SLT_Debug, "exp: %08x", vdps->cfg->expected); + } + else if (mode == VDP_CHK_PANIC) + WRONG("body checksum"); + else + WRONG("mode"); + + return (0); +} + +static const struct vdp xyzzy_vdp_chksha256 = { + .name = "debug.chksha256", + .init = xyzzy_chksha256_init, + .bytes = xyzzy_chksha256_bytes, + .fini = xyzzy_chksha256_fini, +}; + +static const struct vdp xyzzy_vdp_chkcrc32 = { + .name = "debug.chkcrc32", + .init = xyzzy_chkcrc32_init, + .bytes = xyzzy_chkcrc32_bytes, + .fini = xyzzy_chkcrc32_fini, +}; + +#define chkcfg(ws, cfg, magic, id, mode_e) do { \ + struct vmod_priv *p = VRT_priv_task(ctx, id); \ + \ + XXXAN(p); \ + if (p->priv == NULL) { \ + p->priv = WS_Alloc(ws, sizeof *cfg); \ + p->len = sizeof *cfg; \ + } \ + cfg = p->priv; \ + INIT_OBJ(cfg, magic); \ + if (mode_e == VENUM(log)) \ + cfg->mode = VDP_CHK_LOG; \ + else if (mode_e == VENUM(panic)) \ + cfg->mode = VDP_CHK_PANIC; \ + else if (mode_e == VENUM(panic_unless_error)) \ + cfg->mode = VDP_CHK_PANIC_UNLESS_ERROR; \ + else \ + WRONG("mode"); \ +} while(0) + +VCL_VOID v_matchproto_(td_xyzzy_debug_chksha256) +xyzzy_chksha256(VRT_CTX, VCL_BLOB blob, VCL_ENUM mode_e) +{ + struct vdp_chksha256_cfg_s *cfg; + size_t l; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + AN(blob); + XXXAN(blob->blob); + XXXAN(blob->len); + + chkcfg(ctx->ws, cfg, VDP_CHKSHA256_CFG_MAGIC, chksha256_priv_id, mode_e); + + l = blob->len; + if (l > sizeof cfg->expected) + l = sizeof cfg->expected; + memcpy(cfg->expected, blob->blob, l); + +} + +VCL_VOID v_matchproto_(td_xyzzy_debug_chkcrc32) +xyzzy_chkcrc32(VRT_CTX, VCL_INT expected, VCL_ENUM mode_e) +{ + struct vdp_chkcrc32_cfg_s *cfg; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + chkcfg(ctx->ws, cfg, VDP_CHKCRC32_CFG_MAGIC, chkcrc32_priv_id, mode_e); + + if (expected < 0) + expected = 0; + cfg->expected = (uintmax_t)expected % UINT32_MAX; +} + +void +debug_add_filters(VRT_CTX) +{ + AZ(VRT_AddFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_pedantic)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chunked)); + AZ(VRT_AddFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chksha256)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chkcrc32)); +} + +void +debug_remove_filters(VRT_CTX) +{ + VRT_RemoveFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow); + VRT_RemoveFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_pedantic); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chunked); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chksha256); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chkcrc32); +} From dridi.boukelmoune at gmail.com Wed Oct 9 06:27:05 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 9 Oct 2024 06:27:05 +0000 (UTC) Subject: [master] 4aa1ebaa2 Include debug.h in libvmod_debug_la_SOURCES Message-ID: <20241009062705.58B6DA73AB@lists.varnish-cache.org> commit 4aa1ebaa2923e61670d7871e3cf857b1b7d0ac6e Author: Simon Stridsberg Date: Wed Oct 9 07:47:02 2024 +0200 Include debug.h in libvmod_debug_la_SOURCES diff --git a/vmod/automake_boilerplate_debug.am b/vmod/automake_boilerplate_debug.am index f2f2e36ad..51e632f66 100644 --- a/vmod/automake_boilerplate_debug.am +++ b/vmod/automake_boilerplate_debug.am @@ -8,6 +8,7 @@ vmod_LTLIBRARIES += libvmod_debug.la libvmod_debug_la_SOURCES = \ vmod_debug.c \ + vmod_debug.h \ vmod_debug_acl.c \ vmod_debug_dyn.c \ vmod_debug_filters.c \ From nils.goroll at uplex.de Wed Oct 9 11:07:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 9 Oct 2024 11:07:05 +0000 (UTC) Subject: [master] 2c3ae69bd Flexelint Message-ID: <20241009110705.4034FB15D9@lists.varnish-cache.org> commit 2c3ae69bd1de9bab8c11678ad61147e278af69e3 Author: Nils Goroll Date: Wed Oct 9 13:05:36 2024 +0200 Flexelint diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c index dba6c4a68..e0de9ba19 100644 --- a/vmod/vmod_debug_filters.c +++ b/vmod/vmod_debug_filters.c @@ -513,6 +513,7 @@ xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) VSLb(vdc->vsl, SLT_Debug, "sha256 checksum mismatch"); vsb = VSB_new_auto(); + AN(vsb); VSB_quote(vsb, digest, sizeof digest, VSB_QUOTE_HEX); AZ(VSB_finish(vsb)); VSLb(vdc->vsl, SLT_Debug, "got: %s", VSB_data(vsb)); From nils.goroll at uplex.de Mon Oct 14 13:45:07 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 14 Oct 2024 13:45:07 +0000 (UTC) Subject: [master] 1a79fde34 varnishd: truncate thread name on Linux Message-ID: <20241014134507.333C410EE04@lists.varnish-cache.org> commit 1a79fde343ebd9f7210ea2489df6e9730940653f Author: Asad Sajjad Ahmed Date: Fri Oct 11 13:06:16 2024 +0200 varnishd: truncate thread name on Linux On Linux, threads can not have name longer than 15 bytes plus a terminating '\0' byte: > PR_SET_NAME (since Linux 2.6.9) > Set the name of the calling thread, using the value in the loca? > tion pointed to by (char *) arg2. The name can be up to 16 > bytes long, including the terminating null byte. (If the length > of the string, including the terminating null byte, exceeds 16 > bytes, the string is silently truncated.) This is the same at? > tribute that can be set via pthread_setname_np(3) and retrieved > using pthread_getname_np(3). The attribute is likewise accessi? > ble via /proc/self/task/tid/comm (see proc(5)), where tid is the > thread ID of the calling thread, as returned by gettid(2). We have until now ignored the return value from pthread_setname_np(), this is not great as the call then becomes a NOP: > The pthread_setname_np() function can be used to set a > unique name for a thread, which can be useful for debugging multi? > threaded applications. The thread name is a meaningful C language > string, whose length is restricted to 16 characters, including the ter? > minating null byte ('\0'). > [...] > ERANGE The length of the string specified pointed to by name exceeds > the allowed limit. This patch truncates long names to 14 characters plus a tilde ('~') character. Signed-off-by: Asad Sajjad Ahmed diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index d10a70d31..920980b54 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -130,6 +130,22 @@ THR_GetWorker(void) static pthread_key_t name_key; +static void +thr_setname_generic(const char *name) +{ + char buf[16]; + + /* The Linux kernel enforces a strict limitation of 15 bytes name, + * truncate the name if we would overflow it. + */ + if (strlen(name) > 15) { + bprintf(buf, "%.14s~", name); + name = buf; + } + + PTOK(pthread_setname_np(pthread_self(), name)); +} + void THR_SetName(const char *name) { @@ -140,7 +156,7 @@ THR_SetName(const char *name) #elif defined(__NetBSD__) (void)pthread_setname_np(pthread_self(), "%s", (char *)(uintptr_t)name); #else - (void)pthread_setname_np(pthread_self(), name); + thr_setname_generic(name); #endif } From nils.goroll at uplex.de Thu Oct 17 10:39:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 17 Oct 2024 10:39:05 +0000 (UTC) Subject: [master] d7540e548 Minor doc fix Message-ID: <20241017103906.16413657DC@lists.varnish-cache.org> commit d7540e548dc2771a91a1a842949bb82904e06032 Author: Yuri Astrakhan Date: Wed Oct 16 19:24:53 2024 -0400 Minor doc fix `sub vcl_recv` does not have `return (lookup)` diff --git a/doc/sphinx/users-guide/vcl-grace.rst b/doc/sphinx/users-guide/vcl-grace.rst index 3198a6bf1..3d0dafa3a 100644 --- a/doc/sphinx/users-guide/vcl-grace.rst +++ b/doc/sphinx/users-guide/vcl-grace.rst @@ -69,7 +69,7 @@ behave as described above. However, if you want to customize how Varnish behaves, then you should know some of the details on how this works. -When ``sub vcl_recv`` ends with ``return (lookup)`` (which is the +When ``sub vcl_recv`` ends with ``return (hash)`` (which is the default behavior), Varnish will look for a matching object in its cache. Then, if it only found an object whose TTL has run out, Varnish will consider the following: From nils.goroll at uplex.de Thu Oct 24 11:02:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 24 Oct 2024 11:02:06 +0000 (UTC) Subject: [master] 52a6d38c5 sml: fix glitch in "Optimize freebehind (transient) memory usage" Message-ID: <20241024110206.3459C7549@lists.varnish-cache.org> commit 52a6d38c5709cf1a92896d5dc2e984962ce10446 Author: Nils Goroll Date: Thu Oct 24 12:54:51 2024 +0200 sml: fix glitch in "Optimize freebehind (transient) memory usage" Ref 5c2a682aa39af1c61e860f3a62a204d200ac3211 If the checkpoint segment is the stevedore_priv, it has already been removed from the segment list, see sml_trimstore() diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c index 53eb305de..1dea4dc39 100644 --- a/bin/varnishd/storage/storage_simple.c +++ b/bin/varnishd/storage/storage_simple.c @@ -396,9 +396,10 @@ sml_iterator(struct worker *wrk, struct objcore *oc, sl += st->len; st = VTAILQ_PREV(st, storagehead, list); if (final && checkpoint != NULL) { - VTAILQ_REMOVE(&obj->list, checkpoint, list); if (checkpoint == boc->stevedore_priv) boc->stevedore_priv = trim_once; + else + VTAILQ_REMOVE(&obj->list, checkpoint, list); sml_stv_free(stv, checkpoint); } checkpoint = st; From nils.goroll at uplex.de Sun Oct 27 14:10:09 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Sun, 27 Oct 2024 14:10:09 +0000 (UTC) Subject: [master] d5c981a14 Refactor: relax match in take_obj_notnull.cocci to catch more cases Message-ID: <20241027141009.E2576BFEEC@lists.varnish-cache.org> commit d5c981a14e145e00f63cf2a632b225f1c2eaac9e Author: Nils Goroll Date: Sun Oct 27 15:04:24 2024 +0100 Refactor: relax match in take_obj_notnull.cocci to catch more cases We have some places in the code where the verbatim "take obj" semantics do not have setting the pointer to NULL immediately following. diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index a7402ca56..74a7f4e0f 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -345,10 +345,9 @@ vdp_gunzip_fini(struct vdp_ctx *vdc, void **priv) struct vgz *vg; (void)vdc; - CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC); + TAKE_OBJ_NOTNULL(vg, priv, VGZ_MAGIC); AN(vg->m_buf); (void)VGZ_Destroy(&vg); - *priv = NULL; return (0); } diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c index a9a86abc2..8bdd8e8df 100644 --- a/bin/varnishd/cache/cache_range.c +++ b/bin/varnishd/cache/cache_range.c @@ -54,13 +54,13 @@ vrg_range_fini(struct vdp_ctx *vdc, void **priv) struct vrg_priv *vrg_priv; CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); - CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC); + TAKE_OBJ_NOTNULL(vrg_priv, priv, VRG_PRIV_MAGIC); if (vrg_priv->req->resp_len >= 0 && vrg_priv->range_off < vrg_priv->range_high) { Req_Fail(vrg_priv->req, SC_RANGE_SHORT); vrg_priv->req->vdc->retval = -1; } - *priv = NULL; /* struct on ws, no need to free */ + /* struct on ws, no need to free */ return (0); } diff --git a/tools/coccinelle/take_obj_notnull.cocci b/tools/coccinelle/take_obj_notnull.cocci index f99009c06..04ad2f134 100644 --- a/tools/coccinelle/take_obj_notnull.cocci +++ b/tools/coccinelle/take_obj_notnull.cocci @@ -75,13 +75,15 @@ expression obj, priv, magic; @@ - CAST_OBJ_NOTNULL(obj, *priv, magic); -- *priv = NULL; + TAKE_OBJ_NOTNULL(obj, priv, magic); +... +- *priv = NULL; @@ expression obj, priv, magic; @@ - CAST_OBJ_NOTNULL(obj, priv, magic); -- priv = NULL; + TAKE_OBJ_NOTNULL(obj, &priv, magic); +... +- priv = NULL; diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c index e0de9ba19..f810e8d68 100644 --- a/vmod/vmod_debug_filters.c +++ b/vmod/vmod_debug_filters.c @@ -292,11 +292,10 @@ xyzzy_pedantic_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_STATE_MAGIC); + TAKE_OBJ_NOTNULL(vdps, priv, VDP_STATE_MAGIC); assert(vdps->state == VDPS_INIT || vdps->state == VDPS_END); vdps->state = VDPS_FINI; - *priv = NULL; return (0); } @@ -497,8 +496,7 @@ xyzzy_chksha256_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKSHA256_MAGIC); - *priv = NULL; + TAKE_OBJ_NOTNULL(vdps, priv, VDP_CHKSHA256_MAGIC); VSHA256_Final(digest, vdps->cx); r = memcmp(digest, vdps->cfg->expected, sizeof digest); @@ -542,8 +540,7 @@ xyzzy_chkcrc32_fini(struct vdp_ctx *vdc, void **priv) AN(priv); if (*priv == NULL) return (0); - CAST_OBJ_NOTNULL(vdps, *priv, VDP_CHKCRC32_MAGIC); - *priv = NULL; + TAKE_OBJ_NOTNULL(vdps, priv, VDP_CHKCRC32_MAGIC); if (vdps->crc == vdps->cfg->expected) return (0); From nils.goroll at uplex.de Mon Oct 28 12:12:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Oct 2024 12:12:05 +0000 (UTC) Subject: [master] 0883512ed vmod_vtc: Add support for thread workspace operations on the backend side Message-ID: <20241028121205.CA4FA63D74@lists.varnish-cache.org> commit 0883512edae29bf516e749f3ad5e68df25942fb4 Author: Nils Goroll Date: Mon Oct 28 10:09:49 2024 +0100 vmod_vtc: Add support for thread workspace operations on the backend side This is probably useless at the moment because of how the vcl method code checks thread workspace allocations, but at least we avoid a panic at the wrong place. diff --git a/vmod/vmod_vtc.c b/vmod/vmod_vtc.c index 2d97b3543..191282b2b 100644 --- a/vmod/vmod_vtc.c +++ b/vmod/vmod_vtc.c @@ -142,8 +142,10 @@ vtc_ws_find(VRT_CTX, VCL_ENUM which) return (ctx->bo->ws); if (which == VENUM(session)) return (ctx->req->sp->ws); - if (which == VENUM(thread)) + if (which == VENUM(thread) && ctx->req != NULL) return (ctx->req->wrk->aws); + if (which == VENUM(thread) && ctx->bo != NULL) + return (ctx->bo->wrk->aws); WRONG("vtc_ws_find Illegal enum"); } From nils.goroll at uplex.de Mon Oct 28 12:12:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Oct 2024 12:12:05 +0000 (UTC) Subject: [master] ab1eca8c7 vmod_debug: Add a VDP to allocate the thread_workspace Message-ID: <20241028121205.DC9D663D78@lists.varnish-cache.org> commit ab1eca8c73053e59c6a3f366e2cc4ae7f7ae7bcb Author: Nils Goroll Date: Mon Oct 28 10:50:44 2024 +0100 vmod_debug: Add a VDP to allocate the thread_workspace diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c index f810e8d68..68fbb5566 100644 --- a/vmod/vmod_debug_filters.c +++ b/vmod/vmod_debug_filters.c @@ -630,6 +630,41 @@ xyzzy_chkcrc32(VRT_CTX, VCL_INT expected, VCL_ENUM mode_e) cfg->expected = (uintmax_t)expected % UINT32_MAX; } +/********************************************************************** + * reserve thread_workspace + */ + +static int v_matchproto_(vdp_init_f) +xyzzy_awshog_init(VRT_CTX, struct vdp_ctx *vdc, void **priv) +{ + struct ws *aws; + unsigned u; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC); + CHECK_OBJ_ORNULL(vdc->oc, OBJCORE_MAGIC); + CHECK_OBJ_NOTNULL(vdc->hp, HTTP_MAGIC); + AN(vdc->clen); + AN(priv); + + if (ctx->req != NULL) + aws = ctx->req->wrk->aws; + else if (ctx->bo != NULL) + aws = ctx->bo->wrk->aws; + else + WRONG("neither req nor bo"); + + u = WS_ReserveAll(aws); + WS_Release(aws, 0); + (void) WS_Alloc(aws, u); + return (1); +} + +static const struct vdp xyzzy_vdp_awshog = { + .name = "debug.awshog", + .init = xyzzy_awshog_init +}; + void debug_add_filters(VRT_CTX) { @@ -639,6 +674,7 @@ debug_add_filters(VRT_CTX) AZ(VRT_AddFilter(ctx, &xyzzy_vfp_slow, &xyzzy_vdp_slow)); AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chksha256)); AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chkcrc32)); + AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_awshog)); } void @@ -650,4 +686,5 @@ debug_remove_filters(VRT_CTX) VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chunked); VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chksha256); VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chkcrc32); + VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_awshog); } From nils.goroll at uplex.de Mon Oct 28 12:12:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Oct 2024 12:12:05 +0000 (UTC) Subject: [master] 08a898f04 cache_http1_fetch: Refactor error handling in V1F_SendReq() Message-ID: <20241028121206.0380D63D7C@lists.varnish-cache.org> commit 08a898f04bef908cd7ef84ee3c79a2c322e12164 Author: Nils Goroll Date: Mon Oct 28 09:57:28 2024 +0100 cache_http1_fetch: Refactor error handling in V1F_SendReq() diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index e814a7ab7..5536abab3 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -71,6 +71,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, struct http_conn *htc; struct vdp_ctx vdc[1]; intmax_t cl; + const char *err = NULL; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); @@ -97,16 +98,15 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, VDP_Init(vdc, wrk, bo->vsl, NULL, bo, &cl); if (bo->vdp_filter_list != NULL && - VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo)) { - VSLb(bo->vsl, SLT_FetchError, "Failure to push processors"); - VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); - htc->doclose = SC_OVERLOAD; - return (-1); + VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo)) + err = "Failure to push processors"; + else if (v1f_stackv1l(vdc, bo)) { + (void) VDP_Close(vdc, NULL, NULL); + err = "Failure to push V1L"; } - if (v1f_stackv1l(vdc, bo)) { - VSLb(bo->vsl, SLT_FetchError, "Failure to push V1L"); + if (err != NULL) { + VSLb(bo->vsl, SLT_FetchError, "%s", err); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); - (void) VDP_Close(vdc, NULL, NULL); htc->doclose = SC_OVERLOAD; return (-1); } From nils.goroll at uplex.de Mon Oct 28 12:12:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Oct 2024 12:12:06 +0000 (UTC) Subject: [master] f0379c85c cache_http1_fetch: Add V1L_Open() error handling Message-ID: <20241028121206.2AA4E63D81@lists.varnish-cache.org> commit f0379c85cc11fb52ed844c8d815d691e69437e43 Author: Nils Goroll Date: Mon Oct 28 10:52:22 2024 +0100 cache_http1_fetch: Add V1L_Open() error handling With the added test case but without the fix, we would see the panic shown below. Note that I do not see any way how this could be triggered in practice with the current Varnish-Cache core code base. Panic at: Mon, 28 Oct 2024 09:49:57 GMT Assert error in V1L_Write(), http1/cache_http1_line.c line 275: Condition((v1l) != NULL) not true. version = varnish-trunk revision 1b80876384763ffef02d395258401708a814bbb9, vrt api = 20.1 ident = Linux,6.1.0-25-amd64,x86_64,-jnone,-sdefault,-sdefault,-hcritbit,epoll now = 47049.788459 (mono), 1730108997.304734 (real) Backtrace: ip=0x5642a80acdc5 sp=0x7f20c5ca91d0 ip=0x5642a7fe5c83 sp=0x7f20c5ca91f0 ip=0x5642a7fe59ca sp=0x7f20c5ca9210 ip=0x5642a80abff5 sp=0x7f20c5ca9390 ip=0x5642a80356a3 sp=0x7f20c5ca93e0 ip=0x5642a803850b sp=0x7f20c5ca9420 ip=0x5642a8038263 sp=0x7f20c5ca9450 ip=0x5642a80314ef sp=0x7f20c5ca9480 ip=0x5642a7fa5cc0 sp=0x7f20c5ca95b0 ip=0x5642a7fba2de sp=0x7f20c5ca9610 ip=0x5642a7fc9967 sp=0x7f20c5ca96d0 ip=0x5642a7fc8894 sp=0x7f20c5ca9730 ip=0x5642a8023f17 sp=0x7f20c5ca9810 ip=0x5642a8023613 sp=0x7f20c5ca98a0 ip=0x5642a802329b sp=0x7f20c5caa430 ip=0x7f20c61c9144 sp=0x7f20c5caa460 ip=0x7f20c62497dc sp=0x7f20c5caa500 <__xmknodat+0x23c> diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 5536abab3..cb847f1be 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -100,7 +100,17 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, if (bo->vdp_filter_list != NULL && VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo)) err = "Failure to push processors"; + else if (V1L_Open(wrk, wrk->aws, htc->rfd, bo->vsl, nan(""), 0), + wrk->v1l == NULL) { + /* ^^^^^^ + * XXX: need a send_timeout for the backend side + * XXX: use cache_param->http1_iovs ? + */ + (void) VDP_Close(vdc, NULL, NULL); + err = "Failure to open V1L (workspace_thread overflow)"; + } else if (v1f_stackv1l(vdc, bo)) { + (void) V1L_Close(wrk, &bytes); (void) VDP_Close(vdc, NULL, NULL); err = "Failure to push V1L"; } @@ -116,9 +126,6 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, http_PrintfHeader(hp, "Transfer-Encoding: chunked"); VTCP_blocking(*htc->rfd); /* XXX: we should timeout instead */ - /* XXX: need a send_timeout for the backend side */ - // XXX cache_param->http1_iovs ? - V1L_Open(wrk, wrk->aws, htc->rfd, bo->vsl, nan(""), 0); hdrbytes = HTTP1_Write(wrk, hp, HTTP1_Req); /* Deal with any message-body the request might (still) have */ diff --git a/bin/varnishtest/tests/c00029.vtc b/bin/varnishtest/tests/c00029.vtc new file mode 100644 index 000000000..abec8d85a --- /dev/null +++ b/bin/varnishtest/tests/c00029.vtc @@ -0,0 +1,21 @@ +varnishtest "Out of thread workspace when opening V1L on the backend side" + +server s1 { + non_fatal + rxreq +} -start + +varnish v1 -vcl+backend { + import debug; + + sub vcl_backend_fetch { + set bereq.filters += " debug.awshog"; + return (fetch); + } +} -start + +client c1 { + txreq -req "POST" -body "abc" + rxresp + expect resp.status == 503 +} -run From nils.goroll at uplex.de Thu Oct 31 08:51:07 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 08:51:07 +0000 (UTC) Subject: [master] 7665152c7 cache_http1_fetch: Further simplify V1F_SendReq() error handling Message-ID: <20241031085107.5CAF1115A17@lists.varnish-cache.org> commit 7665152c705810e675530d1dd630b713c9e54d3b Author: Nils Goroll Date: Thu Oct 31 09:48:34 2024 +0100 cache_http1_fetch: Further simplify V1F_SendReq() error handling diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index cb847f1be..3e1c8507a 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -69,7 +69,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, ssize_t i; uint64_t bytes, hdrbytes; struct http_conn *htc; - struct vdp_ctx vdc[1]; + struct vdp_ctx vdc[1] = { 0 }; intmax_t cl; const char *err = NULL; @@ -106,15 +106,16 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, * XXX: need a send_timeout for the backend side * XXX: use cache_param->http1_iovs ? */ - (void) VDP_Close(vdc, NULL, NULL); err = "Failure to open V1L (workspace_thread overflow)"; } - else if (v1f_stackv1l(vdc, bo)) { - (void) V1L_Close(wrk, &bytes); - (void) VDP_Close(vdc, NULL, NULL); + else if (v1f_stackv1l(vdc, bo)) err = "Failure to push V1L"; - } + if (err != NULL) { + if (wrk->v1l != NULL) + (void) V1L_Close(wrk, &bytes); + if (vdc->magic != 0) + (void) VDP_Close(vdc, NULL, NULL); VSLb(bo->vsl, SLT_FetchError, "%s", err); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); htc->doclose = SC_OVERLOAD; From dridi at varni.sh Thu Oct 31 10:09:50 2024 From: dridi at varni.sh (Dridi Boukelmoune) Date: Thu, 31 Oct 2024 10:09:50 +0000 Subject: [master] 7665152c7 cache_http1_fetch: Further simplify V1F_SendReq() error handling In-Reply-To: <20241031085107.5CAF1115A17@lists.varnish-cache.org> References: <20241031085107.5CAF1115A17@lists.varnish-cache.org> Message-ID: On Thu, Oct 31, 2024 at 8:51?AM Nils Goroll wrote: > > > commit 7665152c705810e675530d1dd630b713c9e54d3b > Author: Nils Goroll > Date: Thu Oct 31 09:48:34 2024 +0100 > > cache_http1_fetch: Further simplify V1F_SendReq() error handling > > diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c > index cb847f1be..3e1c8507a 100644 > --- a/bin/varnishd/http1/cache_http1_fetch.c > +++ b/bin/varnishd/http1/cache_http1_fetch.c > @@ -69,7 +69,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, > ssize_t i; > uint64_t bytes, hdrbytes; > struct http_conn *htc; > - struct vdp_ctx vdc[1]; > + struct vdp_ctx vdc[1] = { 0 }; > intmax_t cl; > const char *err = NULL; > > @@ -106,15 +106,16 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, > * XXX: need a send_timeout for the backend side > * XXX: use cache_param->http1_iovs ? > */ > - (void) VDP_Close(vdc, NULL, NULL); > err = "Failure to open V1L (workspace_thread overflow)"; > } > - else if (v1f_stackv1l(vdc, bo)) { > - (void) V1L_Close(wrk, &bytes); > - (void) VDP_Close(vdc, NULL, NULL); > + else if (v1f_stackv1l(vdc, bo)) > err = "Failure to push V1L"; > - } > + > if (err != NULL) { > + if (wrk->v1l != NULL) > + (void) V1L_Close(wrk, &bytes); > + if (vdc->magic != 0) > + (void) VDP_Close(vdc, NULL, NULL); Maybe VALID_OBJ? > VSLb(bo->vsl, SLT_FetchError, "%s", err); > VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); > htc->doclose = SC_OVERLOAD; > _______________________________________________ > varnish-commit mailing list > varnish-commit at varnish-cache.org > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit From nils.goroll at uplex.de Thu Oct 31 10:38:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 10:38:05 +0000 (UTC) Subject: [master] 1084cfcbb polish: Further simplify V1F_SendReq() error handling Message-ID: <20241031103805.B621B119671@lists.varnish-cache.org> commit 1084cfcbb574a62a72cdfdd0f74bd0b6b1f5dc04 Author: Nils Goroll Date: Thu Oct 31 11:34:53 2024 +0100 polish: Further simplify V1F_SendReq() error handling Nice polish proposed by Dridi, thank you. BTW, I can no longer read 'Valid Obj' as that, it's now always and forever WALID_OBJ now. All our objects are belong to him. diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 3e1c8507a..2f431bd6d 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -114,7 +114,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, if (err != NULL) { if (wrk->v1l != NULL) (void) V1L_Close(wrk, &bytes); - if (vdc->magic != 0) + if (VALID_OBJ(vdc, VDP_CTX_MAGIC)) (void) VDP_Close(vdc, NULL, NULL); VSLb(bo->vsl, SLT_FetchError, "%s", err); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); From nils.goroll at uplex.de Thu Oct 31 13:38:04 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 13:38:04 +0000 (UTC) Subject: [master] 3bb955ed2 Address a complaint by gcc4.7 on solaris vtesters Message-ID: <20241031133805.060B857B4@lists.varnish-cache.org> commit 3bb955ed2f2674f14f4f959d7e4c01a618fb4dbd Author: Nils Goroll Date: Thu Oct 31 14:37:20 2024 +0100 Address a complaint by gcc4.7 on solaris vtesters diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 2f431bd6d..474175ce0 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -69,7 +69,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, ssize_t i; uint64_t bytes, hdrbytes; struct http_conn *htc; - struct vdp_ctx vdc[1] = { 0 }; + struct vdp_ctx vdc[1] = {{ 0 }}; intmax_t cl; const char *err = NULL; From nils.goroll at uplex.de Thu Oct 31 13:44:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 13:44:05 +0000 (UTC) Subject: [master] 80a41345a Silence Flexelint Message-ID: <20241031134405.C0F8E5D10@lists.varnish-cache.org> commit 80a41345ae5c166ebba590def6ba48d899074c01 Author: Nils Goroll Date: Thu Oct 31 14:39:28 2024 +0100 Silence Flexelint diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 920980b54..f33aea55d 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -143,6 +143,7 @@ thr_setname_generic(const char *name) name = buf; } + //lint --e{438} Last value assigned not used PTOK(pthread_setname_np(pthread_self(), name)); } diff --git a/flint.lnt b/flint.lnt index d338254b0..65d641676 100644 --- a/flint.lnt +++ b/flint.lnt @@ -181,6 +181,7 @@ -emacro(731, xxxassert) // arg to eq/non-eq -emacro(527, WRONG) // unreachable code -emacro(774, VALID_OBJ) // boolean always true +-emacro(506, VALID_OBJ) // Constant value Boolean -emacro(506, v_static_assert) // Constant value Boolean -esym(751, __vassert_*) // local typedef '___' (___) not referenced From nils.goroll at uplex.de Thu Oct 31 13:57:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 13:57:05 +0000 (UTC) Subject: [master] 41f53eaf5 Our SunCC is too old. Message-ID: <20241031135705.662966652@lists.varnish-cache.org> commit 41f53eaf53630cc7feed3e4228529f2ef897e6dc Author: Nils Goroll Date: Thu Oct 31 14:55:35 2024 +0100 Our SunCC is too old. Someone(tm) needs to upgrade it seems... diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 474175ce0..bf05b0e14 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -69,7 +69,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, ssize_t i; uint64_t bytes, hdrbytes; struct http_conn *htc; - struct vdp_ctx vdc[1] = {{ 0 }}; + struct vdp_ctx vdc[1]; intmax_t cl; const char *err = NULL; @@ -96,6 +96,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, else cl = 0; + vdc->magic = 0; VDP_Init(vdc, wrk, bo->vsl, NULL, bo, &cl); if (bo->vdp_filter_list != NULL && VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo)) From nils.goroll at uplex.de Thu Oct 31 14:12:04 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 14:12:04 +0000 (UTC) Subject: [master] b662a8894 Revert "Our SunCC is too old." Message-ID: <20241031141204.F0E65726F@lists.varnish-cache.org> commit b662a88948384d81f048c2360e6fef2f6d56fd07 Author: Nils Goroll Date: Thu Oct 31 15:10:21 2024 +0100 Revert "Our SunCC is too old." Sorry, I was looking at the wrong place. It seems the errors reported by suncc are rather related to a recent global zone update. This reverts commit 41f53eaf53630cc7feed3e4228529f2ef897e6dc. diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index bf05b0e14..474175ce0 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -69,7 +69,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, ssize_t i; uint64_t bytes, hdrbytes; struct http_conn *htc; - struct vdp_ctx vdc[1]; + struct vdp_ctx vdc[1] = {{ 0 }}; intmax_t cl; const char *err = NULL; @@ -96,7 +96,6 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, else cl = 0; - vdc->magic = 0; VDP_Init(vdc, wrk, bo->vsl, NULL, bo, &cl); if (bo->vdp_filter_list != NULL && VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo)) From nils.goroll at uplex.de Thu Oct 31 15:29:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 15:29:05 +0000 (UTC) Subject: [master] 0a789f173 v_static_assert vs. stdc Message-ID: <20241031152905.3D44B631DA@lists.varnish-cache.org> commit 0a789f173413e2dbadc9c361e71a3585d4b36263 Author: Nils Goroll Date: Thu Oct 31 16:26:14 2024 +0100 v_static_assert vs. stdc C11 has _Static_assert and static_assert via assert.h, which we can not include. C23 has static_assert and deprecated _Static_assert diff --git a/include/vas.h b/include/vas.h index 2e6a9ee2a..75c8247c3 100644 --- a/include/vas.h +++ b/include/vas.h @@ -114,7 +114,11 @@ do { \ # define __has_extension(x) 0 #endif -#if __has_extension(c_static_assert) +#if __STDC_VERSION__ - 0 >= 202311L +# define v_static_assert static_assert +#elif __STDC_VERSION__ - 0 >= 201112L +# define v_static_assert _Static_assert +#elif __has_extension(c_static_assert) # define v_static_assert _Static_assert #elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) # define v_static_assert _Static_assert From nils.goroll at uplex.de Thu Oct 31 20:31:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 20:31:06 +0000 (UTC) Subject: [master] 2bd3a2f58 Initialize static const variables Message-ID: <20241031203106.1FF6E106E6C@lists.varnish-cache.org> commit 2bd3a2f5869d470b67faba88131a2d2fda5eac6e Author: Nils Goroll Date: Thu Oct 31 21:01:03 2024 +0100 Initialize static const variables Reported by Su^WOracle CC 12.6 diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c index 6bf1ba06e..18077c220 100644 --- a/bin/varnishd/cache/cache_vrt_filter.c +++ b/bin/varnishd/cache/cache_vrt_filter.c @@ -188,7 +188,7 @@ VRT_RemoveVDP(VRT_CTX, const struct vdp *filter) VRT_RemoveFilter(ctx, NULL, filter); } -static const struct vfilter vfilter_error[1]; +static const struct vfilter vfilter_error[1] = {{0}}; // XXX: idea(fgs): Allow filters (...) arguments in the list static const struct vfilter * diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c index 259497f8d..7e399f7b7 100644 --- a/vmod/vmod_debug.c +++ b/vmod/vmod_debug.c @@ -67,8 +67,8 @@ static pthread_mutex_t vsc_mtx = PTHREAD_MUTEX_INITIALIZER; static struct vsc_seg *vsc_seg = NULL; static struct VSC_debug *vsc = NULL; static int loads; -static const int store_ip_token; -static const int fail_task_fini_token; +static const int store_ip_token = 0; +static const int fail_task_fini_token = 0; extern void mylog(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...) v_printflike_(3,4); From nils.goroll at uplex.de Thu Oct 31 20:31:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 20:31:06 +0000 (UTC) Subject: [master] b86f51495 Make builds work with SunCC 12.6 Message-ID: <20241031203106.3886B106E6F@lists.varnish-cache.org> commit b86f5149566202ebe99c85c428672b06676a155d Author: Nils Goroll Date: Thu Oct 31 21:03:46 2024 +0100 Make builds work with SunCC 12.6 this afternoon, I went down a rabbit hole of the unpleasent kind: Our SunCC 12.4 vtester stopped working after an upgrade of the "host" (global zone), for reasons which I have not fully understood: "VSC_lck.c", line 22: can not declare variably modified type at file scope (E_CANT_DECL_FILESCOPE_VM) "VSC_lck.c", line 23: can not declare variably modified type at file scope (E_CANT_DECL_FILESCOPE_VM) ... The immediate cause for this is that the fallback for v_static_assert was used, which would fail the compilation for the reason given (somehow justified). While SunCC 12.4 offers a -std=c11 option, that would only give an __STDC_VERSION__ of 1999something, which we can not safely assume to support native static asserts. And making E_CANT_DECL_FILESCOPE_VM non-fatal seemed to be too high a price. After not seeing a way to make the old compiler work again while retaining some usefulness (I have _no_ clue as to why the behavior changed, because the compiler suite binaries were not touched at all), I tried to make a later version work. Which was a success in the sense that it would compile again without ugly hacks around v_static_assert, but was a failure in the sense that a _lot_ of warnings had to be made non-fatal. Which, given that compiler warnings are one of the main reasons for having a variety of compilers to begin with, brought me close to the point of simply giving up on SunCC. In the end, there was _one_ new warning which I did not suppress and rather addressed in the source code (see previous commit). For the other issues I saw no satisfactory changes to the source, so I made the respective warnings non-fatal: * no%E_END_OF_LOOP_CODE_NOT_REACHED For patterns like do { /* ... */ return; } while (0) I really do not see much sense in avoiding this pattern * no%E_UNRECOGNIZED_PRAGMA_IGNORED Harmless complaints about #pragma GCC * no%E_STATEMENT_NOT_REACHED no%E_FUNC_HAS_NO_RETURN_STMT SunCC now complains about NEEDLESS() statements which we had added because ... SunCC complained. Facepalm... * no%E_INITIALIZATION_TYPE_MISMATCH no%E_ARG_INCOMPATIBLE_WITH_ARG_L no%E_ASSIGNMENT_TYPE_MISMATCH These all concern function pointers set to / passed as NULL. Yes, NULL defined as (void *)0 is not a valid function pointer, true, but I really see no sense in changing all these places to just 0 or add casts... * no%E_FUNC_NO_RET_RET SunCC now thinks that functions which we declared noreturn might return. I checked one case which absolutely would never return because of an exit(2). Why on earth SunCC would think it still would, I have no idea. * -xatomic=studio This was necessary because SunCC would not automatically link to its atomic library, despite the documentation saying it would. Version used: $ cc -V cc: Studio 12.6 Sun C 5.15 SunOS_i386 2017/05/30 diff --git a/configure.ac b/configure.ac index f0d1a3b1f..b36c599f3 100644 --- a/configure.ac +++ b/configure.ac @@ -675,8 +675,9 @@ AX_CHECK_COMPILE_FLAG([-Wall], if test "$SUNCC" = "yes" ; then SUNCC_CFLAGS=" \ - -errwarn=%all,no%E_EMPTY_TRANSLATION_UNIT \ + -errwarn=%all,no%E_EMPTY_TRANSLATION_UNIT,no%E_END_OF_LOOP_CODE_NOT_REACHED,no%E_UNRECOGNIZED_PRAGMA_IGNORED,no%E_STATEMENT_NOT_REACHED,no%E_INITIALIZATION_TYPE_MISMATCH,no%E_ARG_INCOMPATIBLE_WITH_ARG_L,no%E_ASSIGNMENT_TYPE_MISMATCH,no%E_FUNC_HAS_NO_RETURN_STMT,no%E_FUNC_NO_RET_RET \ -errtags=yes \ + -xatomic=studio \ " AX_CHECK_COMPILE_FLAG([${SUNCC_CFLAGS}], [CFLAGS="${CFLAGS} ${SUNCC_CFLAGS}" From nils.goroll at uplex.de Thu Oct 31 20:49:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 31 Oct 2024 20:49:05 +0000 (UTC) Subject: [master] fe0e29e0c Fix literal integer types Message-ID: <20241031204905.822E8107AB1@lists.varnish-cache.org> commit fe0e29e0cb10b3aad123cf6d1baccf4641868ed8 Author: Nils Goroll Date: Thu Oct 31 21:47:36 2024 +0100 Fix literal integer types Reported by SunCC 32bit diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c index dc3f55a77..066be91d3 100644 --- a/bin/varnishd/proxy/cache_proxy_proto.c +++ b/bin/varnishd/proxy/cache_proxy_proto.c @@ -164,70 +164,70 @@ static const char vpx2_sig[] = { }; static const uint32_t crctable[256] = { - 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, - 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, - 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, - 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, - 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, - 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, - 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, - 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL, - 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, - 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L, - 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, - 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, - 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, - 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL, - 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, - 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L, - 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, - 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L, - 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, - 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L, - 0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, - 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, - 0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, - 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L, - 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, - 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, - 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, - 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L, - 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, - 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L, - 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, - 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L, - 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, - 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L, - 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, - 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, - 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, - 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL, - 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, - 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L, - 0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, - 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, - 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, - 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L, - 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, - 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, - 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, - 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL, - 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, - 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL, - 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, - 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L, - 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, - 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L, - 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, - 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, - 0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, - 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L, - 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L, - 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL, - 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, - 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, - 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, - 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L + 0x00000000UL, 0xF26B8303UL, 0xE13B70F7UL, 0x1350F3F4UL, + 0xC79A971FUL, 0x35F1141CUL, 0x26A1E7E8UL, 0xD4CA64EBUL, + 0x8AD958CFUL, 0x78B2DBCCUL, 0x6BE22838UL, 0x9989AB3BUL, + 0x4D43CFD0UL, 0xBF284CD3UL, 0xAC78BF27UL, 0x5E133C24UL, + 0x105EC76FUL, 0xE235446CUL, 0xF165B798UL, 0x030E349BUL, + 0xD7C45070UL, 0x25AFD373UL, 0x36FF2087UL, 0xC494A384UL, + 0x9A879FA0UL, 0x68EC1CA3UL, 0x7BBCEF57UL, 0x89D76C54UL, + 0x5D1D08BFUL, 0xAF768BBCUL, 0xBC267848UL, 0x4E4DFB4BUL, + 0x20BD8EDEUL, 0xD2D60DDDUL, 0xC186FE29UL, 0x33ED7D2AUL, + 0xE72719C1UL, 0x154C9AC2UL, 0x061C6936UL, 0xF477EA35UL, + 0xAA64D611UL, 0x580F5512UL, 0x4B5FA6E6UL, 0xB93425E5UL, + 0x6DFE410EUL, 0x9F95C20DUL, 0x8CC531F9UL, 0x7EAEB2FAUL, + 0x30E349B1UL, 0xC288CAB2UL, 0xD1D83946UL, 0x23B3BA45UL, + 0xF779DEAEUL, 0x05125DADUL, 0x1642AE59UL, 0xE4292D5AUL, + 0xBA3A117EUL, 0x4851927DUL, 0x5B016189UL, 0xA96AE28AUL, + 0x7DA08661UL, 0x8FCB0562UL, 0x9C9BF696UL, 0x6EF07595UL, + 0x417B1DBCUL, 0xB3109EBFUL, 0xA0406D4BUL, 0x522BEE48UL, + 0x86E18AA3UL, 0x748A09A0UL, 0x67DAFA54UL, 0x95B17957UL, + 0xCBA24573UL, 0x39C9C670UL, 0x2A993584UL, 0xD8F2B687UL, + 0x0C38D26CUL, 0xFE53516FUL, 0xED03A29BUL, 0x1F682198UL, + 0x5125DAD3UL, 0xA34E59D0UL, 0xB01EAA24UL, 0x42752927UL, + 0x96BF4DCCUL, 0x64D4CECFUL, 0x77843D3BUL, 0x85EFBE38UL, + 0xDBFC821CUL, 0x2997011FUL, 0x3AC7F2EBUL, 0xC8AC71E8UL, + 0x1C661503UL, 0xEE0D9600UL, 0xFD5D65F4UL, 0x0F36E6F7UL, + 0x61C69362UL, 0x93AD1061UL, 0x80FDE395UL, 0x72966096UL, + 0xA65C047DUL, 0x5437877EUL, 0x4767748AUL, 0xB50CF789UL, + 0xEB1FCBADUL, 0x197448AEUL, 0x0A24BB5AUL, 0xF84F3859UL, + 0x2C855CB2UL, 0xDEEEDFB1UL, 0xCDBE2C45UL, 0x3FD5AF46UL, + 0x7198540DUL, 0x83F3D70EUL, 0x90A324FAUL, 0x62C8A7F9UL, + 0xB602C312UL, 0x44694011UL, 0x5739B3E5UL, 0xA55230E6UL, + 0xFB410CC2UL, 0x092A8FC1UL, 0x1A7A7C35UL, 0xE811FF36UL, + 0x3CDB9BDDUL, 0xCEB018DEUL, 0xDDE0EB2AUL, 0x2F8B6829UL, + 0x82F63B78UL, 0x709DB87BUL, 0x63CD4B8FUL, 0x91A6C88CUL, + 0x456CAC67UL, 0xB7072F64UL, 0xA457DC90UL, 0x563C5F93UL, + 0x082F63B7UL, 0xFA44E0B4UL, 0xE9141340UL, 0x1B7F9043UL, + 0xCFB5F4A8UL, 0x3DDE77ABUL, 0x2E8E845FUL, 0xDCE5075CUL, + 0x92A8FC17UL, 0x60C37F14UL, 0x73938CE0UL, 0x81F80FE3UL, + 0x55326B08UL, 0xA759E80BUL, 0xB4091BFFUL, 0x466298FCUL, + 0x1871A4D8UL, 0xEA1A27DBUL, 0xF94AD42FUL, 0x0B21572CUL, + 0xDFEB33C7UL, 0x2D80B0C4UL, 0x3ED04330UL, 0xCCBBC033UL, + 0xA24BB5A6UL, 0x502036A5UL, 0x4370C551UL, 0xB11B4652UL, + 0x65D122B9UL, 0x97BAA1BAUL, 0x84EA524EUL, 0x7681D14DUL, + 0x2892ED69UL, 0xDAF96E6AUL, 0xC9A99D9EUL, 0x3BC21E9DUL, + 0xEF087A76UL, 0x1D63F975UL, 0x0E330A81UL, 0xFC588982UL, + 0xB21572C9UL, 0x407EF1CAUL, 0x532E023EUL, 0xA145813DUL, + 0x758FE5D6UL, 0x87E466D5UL, 0x94B49521UL, 0x66DF1622UL, + 0x38CC2A06UL, 0xCAA7A905UL, 0xD9F75AF1UL, 0x2B9CD9F2UL, + 0xFF56BD19UL, 0x0D3D3E1AUL, 0x1E6DCDEEUL, 0xEC064EEDUL, + 0xC38D26C4UL, 0x31E6A5C7UL, 0x22B65633UL, 0xD0DDD530UL, + 0x0417B1DBUL, 0xF67C32D8UL, 0xE52CC12CUL, 0x1747422FUL, + 0x49547E0BUL, 0xBB3FFD08UL, 0xA86F0EFCUL, 0x5A048DFFUL, + 0x8ECEE914UL, 0x7CA56A17UL, 0x6FF599E3UL, 0x9D9E1AE0UL, + 0xD3D3E1ABUL, 0x21B862A8UL, 0x32E8915CUL, 0xC083125FUL, + 0x144976B4UL, 0xE622F5B7UL, 0xF5720643UL, 0x07198540UL, + 0x590AB964UL, 0xAB613A67UL, 0xB831C993UL, 0x4A5A4A90UL, + 0x9E902E7BUL, 0x6CFBAD78UL, 0x7FAB5E8CUL, 0x8DC0DD8FUL, + 0xE330A81AUL, 0x115B2B19UL, 0x020BD8EDUL, 0xF0605BEEUL, + 0x24AA3F05UL, 0xD6C1BC06UL, 0xC5914FF2UL, 0x37FACCF1UL, + 0x69E9F0D5UL, 0x9B8273D6UL, 0x88D28022UL, 0x7AB90321UL, + 0xAE7367CAUL, 0x5C18E4C9UL, 0x4F48173DUL, 0xBD23943EUL, + 0xF36E6F75UL, 0x0105EC76UL, 0x12551F82UL, 0xE03E9C81UL, + 0x34F4F86AUL, 0xC69F7B69UL, 0xD5CF889DUL, 0x27A40B9EUL, + 0x79B737BAUL, 0x8BDCB4B9UL, 0x988C474DUL, 0x6AE7C44EUL, + 0xBE2DA0A5UL, 0x4C4623A6UL, 0x5F16D052UL, 0xAD7D5351UL }; static uint32_t crc32c(const uint8_t *buf, int len) diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c index 6e61ff393..af46aa665 100644 --- a/lib/libvarnish/vtim.c +++ b/lib/libvarnish/vtim.c @@ -585,8 +585,8 @@ parse_check(time_t t, const char *s) } } -#define TTEST_MIN (sizeof(time_t) >= 8 ? -2209852800 : INT32_MIN) -#define TTEST_MAX (sizeof(time_t) >= 8 ? 20000000000 : INT32_MAX) +#define TTEST_MIN (sizeof(time_t) >= 8 ? -2209852800LL : INT32_MIN) +#define TTEST_MAX (sizeof(time_t) >= 8 ? 20000000000LL : INT32_MAX) int main(int argc, char **argv)