[master] 9d40af77f vsmw: make segment ids input validation stricter

Nils Goroll nils.goroll at uplex.de
Mon Jun 3 13:20:05 UTC 2024


commit 9d40af77fb153489e0f8c95b61de08a0daf15fb7
Author: Stephane Cance <stephane.cance at varnish-software.com>
Date:   Tue May 14 15:41:12 2024 +0200

    vsmw: make segment ids input validation stricter

diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 2ca388b06..5ca509e34 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -381,6 +381,7 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc,
     const char *fmt, va_list va)
 {
 	struct vsmwseg *seg;
+	ssize_t l;
 
 	vsmw_do_lock();
 	CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC);
@@ -391,13 +392,20 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc,
 	seg->len = PRNDUP(payload);
 
 	VSB_clear(vsmw->vsb);
-	if (prefix != NULL)
+	if (prefix != NULL) {
+		assert(prefix[0] != '\0');
 		VSB_cat(vsmw->vsb, prefix);
-	if (prefix != NULL && fmt[0] != '\0')
-		VSB_cat(vsmw->vsb, ".");
+		if (fmt[0] != '\0')
+			VSB_cat(vsmw->vsb, ".");
+	}
+	l = VSB_len(vsmw->vsb);
+	assert(l >= 0);
 	VSB_vprintf(vsmw->vsb, fmt, va);
 	AZ(VSB_finish(vsmw->vsb));
+	assert(fmt[0] == '\0' || l < VSB_len(vsmw->vsb));
+
 	REPLACE(seg->id, VSB_data(vsmw->vsb));
+	AN(seg->id);
 
 	if (vc == NULL)
 		vc = vsmw_newcluster(vsmw, seg->len, category);


More information about the varnish-commit mailing list