[master] e787ff486 storage_simple: mark buffers

Nils Goroll nils.goroll at uplex.de
Wed Jan 29 14:50:10 UTC 2025


commit e787ff486e07ea32fa23f4226d7be137e91adf8e
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Nov 19 10:27:23 2024 +0100

    storage_simple: mark buffers
    
    Make sure that we do not confuse buffers with object data.
    
    The flags field comes at no extra memory cost on 64bit. For 32bit, this change
    breaks binary compatibility with any out-of-tree storages using storage_simple.

diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index 1dea4dc39..8c81c85ee 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -184,6 +184,7 @@ SML_AllocBuf(struct worker *wrk, const struct stevedore *stv, size_t size,
 	if (st == NULL)
 		return (NULL);
 	assert(st->space >= size);
+	st->flags = STORAGE_F_BUFFER;
 	st->len = size;
 	*ppriv = (uintptr_t)st;
 	return (st->ptr);
@@ -198,6 +199,7 @@ SML_FreeBuf(struct worker *wrk, const struct stevedore *stv, uintptr_t priv)
 	CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
 
 	CAST_OBJ_NOTNULL(st, (void *)priv, STORAGE_MAGIC);
+	assert(st->flags == STORAGE_F_BUFFER);
 	sml_stv_free(stv, st);
 }
 
diff --git a/bin/varnishd/storage/storage_simple.h b/bin/varnishd/storage/storage_simple.h
index 881e0b857..207a11505 100644
--- a/bin/varnishd/storage/storage_simple.h
+++ b/bin/varnishd/storage/storage_simple.h
@@ -38,7 +38,8 @@
 struct storage {
 	unsigned		magic;
 #define STORAGE_MAGIC		0x1a4e51c0
-
+	unsigned		flags;
+#define STORAGE_F_BUFFER	1
 
 	VTAILQ_ENTRY(storage)	list;
 	void			*priv;


More information about the varnish-commit mailing list