[master] 23f8e3407 ws: Ban direct access to the workspace id
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Aug 31 18:41:11 UTC 2020
commit 23f8e3407d0ce6dc6a411e33d9ba16a079d06302
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed May 6 22:58:07 2020 +0200
ws: Ban direct access to the workspace id
From this point on, only cache_ws.c fiddles with struct ws, which needs
to remain visible in order to be embeddable in other data structures. We
have an API covering all use cases in tree, except vmod_vtc operations
that violate the contract to provide a rudimentary dump in VCL for test
purposes.
Inline functions provided in headers aren't considered a problem here.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index fb8e11f0b..b3ae30c99 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -136,10 +136,12 @@ struct lock { void *priv; }; // Opaque
* Workspace structure for quick memory allocation.
*/
+#define WS_ID_SIZE 4
+
struct ws {
unsigned magic;
#define WS_MAGIC 0x35fac554
- char id[4]; /* identity */
+ char id[WS_ID_SIZE]; /* identity */
char *s; /* (S)tart of buffer */
char *f; /* (F)ree/front pointer */
char *r; /* (R)eserved length */
@@ -793,6 +795,7 @@ int WS_Overflowed(const struct ws *ws);
const char *WS_Printf(struct ws *ws, const char *fmt, ...) v_printflike_(2, 3);
int WS_Inside(const struct ws *, const void *, const void *);
void WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len);
+void WS_Id(const struct ws *ws, char *id);
void WS_VSB_new(struct vsb *, struct ws *);
char *WS_VSB_finish(struct vsb *, struct ws *, size_t *);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 1c608ff3a..9fa4c1f64 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -112,10 +112,11 @@ http_VSL_log(const struct http *hp)
static void
http_fail(const struct http *hp)
{
+ char id[WS_ID_SIZE];
VSC_C_main->losthdr++;
- hp->ws->id[0] |= 0x20; // cheesy tolower()
- VSLb(hp->vsl, SLT_Error, "out of workspace (%s)", hp->ws->id);
+ WS_Id(hp->ws, id);
+ VSLb(hp->vsl, SLT_Error, "out of workspace (%s)", id);
WS_MarkOverflow(hp->ws);
}
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index b4dc26435..c8fb32210 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -114,6 +114,16 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
WS_Assert(ws);
}
+void
+WS_Id(const struct ws *ws, char *id)
+{
+
+ WS_Assert(ws);
+ AN(id);
+ memcpy(id, ws->id, WS_ID_SIZE);
+ id[0] |= 0x20; // cheesy tolower()
+}
+
void
WS_MarkOverflow(struct ws *ws)
{
More information about the varnish-commit
mailing list