[master] 9b31fcdcd vsl: Coveritification
Nils Goroll
nils.goroll at uplex.de
Tue Jun 3 15:21:05 UTC 2025
commit 9b31fcdcd6d1638e7f0e4baa3c21567970e0b642
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Jun 3 17:17:44 2025 +0200
vsl: Coveritification
CID1605309 reports a potential "cast overflow" for l = VSL_OVERHEAD +
VSL_WORDS(VSL_LEN(c->buf));
This can not happen because VSL_LEN is limited to UINT16_MAX plus VSL_OVERHEAD
(3). Hopefully the explicit cast will make this clear.
diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h
index 87d38b04c..b220a82e3 100644
--- a/include/vapi/vsl_int.h
+++ b/include/vapi/vsl_int.h
@@ -81,14 +81,14 @@
#define VSL_VERSHIFT 16
#define VSL_IDMASK 0xff
#define VSL_IDSHIFT 24
-#define VSL_OVERHEAD 3
+#define VSL_OVERHEAD 3U
#define VSL_VERSION_2 0x0
#define VSL_VERSION_3 0x1
#define VSL_WORDS(len) (((len) + 3) / 4)
#define VSL_BYTES(words) ((words) * 4)
#define VSL_END(ptr, len) ((ptr) + VSL_OVERHEAD + VSL_WORDS(len))
#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr))
-#define VSL_LEN(ptr) ((ptr)[0] & VSL_LENMASK)
+#define VSL_LEN(ptr) ((uint16_t)((ptr)[0] & VSL_LENMASK))
#define VSL_VER(ptr) (((ptr)[0] >> VSL_VERSHIFT) & VSL_VERMASK)
#define VSL_TAG(ptr) ((enum VSL_tag_e)((ptr)[0] >> VSL_IDSHIFT))
#define VSL_ID64(ptr) (((uint64_t)((ptr)[2])<<32) | ((ptr)[1]))
More information about the varnish-commit
mailing list