[master] 1beb644ec Add VRT support for VCL_INTEGER and VCL_REAL validity

Poul-Henning Kamp phk at FreeBSD.org
Wed May 19 12:29:06 UTC 2021


commit 1beb644ec4356ff87281d03b3d583130816a1695
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed May 19 10:58:11 2021 +0000

    Add VRT support for VCL_INTEGER and VCL_REAL validity

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 59ebaf697..82cd54e53 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -817,6 +817,13 @@ VRT_IP_string(VRT_CTX, VCL_IP ip)
 	return (p);
 }
 
+int
+VRT_INT_is_valid(VCL_INT arg)
+{
+	return (arg >= VRT_INTEGER_MIN && arg <= VRT_INTEGER_MAX);
+}
+
+
 VCL_STRING v_matchproto_()
 VRT_INT_string(VRT_CTX, VCL_INT num)
 {
@@ -825,6 +832,12 @@ VRT_INT_string(VRT_CTX, VCL_INT num)
 	return (WS_Printf(ctx->ws, "%jd", (intmax_t)num));
 }
 
+int
+VRT_REAL_is_valid(VCL_REAL arg)
+{
+	return (!isnan(arg) && arg >= VRT_DECIMAL_MIN && arg <= VRT_DECIMAL_MAX);
+}
+
 VCL_STRING v_matchproto_()
 VRT_REAL_string(VRT_CTX, VCL_REAL num)
 {
diff --git a/include/vrt.h b/include/vrt.h
index 10528a3e5..31198fc95 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -301,6 +301,16 @@ typedef vtim_real				VCL_TIME;
 typedef struct vcl *				VCL_VCL;
 typedef void					VCL_VOID;
 
+/*
+ * These limits track RFC8941
+ * We use hex notation because 999999999999.999 is not perfectly
+ * representable in ieee64 doubles.
+ */
+#define VRT_INTEGER_MAX 999999999999999
+#define VRT_INTEGER_MIN -999999999999999
+#define VRT_DECIMAL_MAX 0x1.d1a94a1fffff8p+39
+#define VRT_DECIMAL_MIN -0x1.d1a94a1fffff8p+39
+
 /***********************************************************************
  * This is the composite "context" argument for compiled VCL, VRT and
  * VMOD functions.
@@ -412,11 +422,17 @@ VCL_BACKEND VRT_DirectorResolve(VRT_CTX, VCL_BACKEND);
 /* VCL_BLOB */
 VCL_BLOB VRT_blob(VRT_CTX, const char *, const void *, size_t, unsigned);
 
+/* VCL_INT */
+int VRT_INT_is_valid(VCL_INT);
+
 /* VCL_IP */
 int VRT_VSA_GetPtr(VRT_CTX, VCL_IP sua, const unsigned char ** dst);
 VCL_BOOL VRT_ipcmp(VRT_CTX, VCL_IP, VCL_IP);
 void VRT_Format_Proxy(struct vsb *, VCL_INT, VCL_IP, VCL_IP, VCL_STRING);
 
+/* VCL_REAL */
+int VRT_REAL_is_valid(VCL_REAL);
+
 /* VCL_REGEX */
 VCL_BOOL VRT_re_match(VRT_CTX, VCL_STRING, VCL_REGEX);
 VCL_STRING VRT_regsub(VRT_CTX, int all, VCL_STRING, VCL_REGEX, VCL_STRING);


More information about the varnish-commit mailing list