[master] 36477c6f6 Do not allow reservation of len <= 0 sess_attrs

Poul-Henning Kamp phk at FreeBSD.org
Mon Nov 11 10:34:06 UTC 2019


commit 36477c6f6f2e68f1a76938cd03229e514ef01cb7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Nov 11 10:32:58 2019 +0000

    Do not allow reservation of len <= 0 sess_attrs

diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 548674bec..afda89314 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -132,19 +132,21 @@ ses_reserve_attr(struct sess *sp, enum sess_attr a, void **dst, int sz)
 	int								\
 	SES_Set_##low(const struct sess *sp, const typ *src)		\
 	{								\
+		assert(len > 0);					\
 		return (ses_set_attr(sp, SA_##UP, src, len));		\
 	}								\
 									\
 	int								\
 	SES_Get_##low(const struct sess *sp, typ **dst)			\
 	{								\
+		assert(len > 0);					\
 		return (ses_get_attr(sp, SA_##UP, (void**)dst));	\
 	}								\
 									\
 	void								\
 	SES_Reserve_##low(struct sess *sp, typ **dst)			\
 	{								\
-		assert(len >= 0);					\
+		assert(len > 0);					\
 		ses_reserve_attr(sp, SA_##UP, (void**)dst, len);	\
 	}
 
diff --git a/include/tbl/sess_attr.h b/include/tbl/sess_attr.h
index f4f4de0b0..e61365c4d 100644
--- a/include/tbl/sess_attr.h
+++ b/include/tbl/sess_attr.h
@@ -38,8 +38,8 @@ SESS_ATTR(REMOTE_ADDR,	  remote_addr,	struct suckaddr,    vsa_suckaddr_len)
 SESS_ATTR(LOCAL_ADDR,	  local_addr,	struct suckaddr,    vsa_suckaddr_len)
 SESS_ATTR(CLIENT_ADDR,	  client_addr,	struct suckaddr,    vsa_suckaddr_len)
 SESS_ATTR(SERVER_ADDR,	  server_addr,	struct suckaddr,    vsa_suckaddr_len)
-SESS_ATTR(CLIENT_IP,	  client_ip,	char,		    -1)
-SESS_ATTR(CLIENT_PORT,	  client_port,	char,		    -1)
+SESS_ATTR(CLIENT_IP,	  client_ip,	char,		    0)
+SESS_ATTR(CLIENT_PORT,	  client_port,	char,		    0)
 SESS_ATTR(PROXY_TLV,	  proxy_tlv,	uintptr_t,	    sizeof(uintptr_t))
 SESS_ATTR(PROTO_PRIV,	  proto_priv,	uintptr_t,	    sizeof(uintptr_t))
 #undef SESS_ATTR


More information about the varnish-commit mailing list