[master] 929e94b5c lck: Check lock pointers before dereferencing them

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon May 10 15:24:04 UTC 2021


commit 929e94b5c5516d06d3d8d92fe70d0c32f91f9303
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon May 10 17:17:52 2021 +0200

    lck: Check lock pointers before dereferencing them

diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 3e507119c..32b326ee1 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -115,6 +115,7 @@ Lck__Lock(struct lock *lck, const char *p, int l)
 	struct ilck *ilck;
 	int r = EINVAL;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	if (DO_DEBUG(DBG_WITNESS))
 		Lck_Witness_Lock(ilck, p, l, "");
@@ -140,6 +141,7 @@ Lck__Unlock(struct lock *lck, const char *p, int l)
 	(void)p;
 	(void)l;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	assert(pthread_equal(ilck->owner, pthread_self()));
 	AN(ilck->held);
@@ -170,6 +172,7 @@ Lck__Trylock(struct lock *lck, const char *p, int l)
 	struct ilck *ilck;
 	int r;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	if (DO_DEBUG(DBG_WITNESS))
 		Lck_Witness_Lock(ilck, p, l, "?");
@@ -190,6 +193,7 @@ Lck__Held(const struct lock *lck)
 {
 	struct ilck *ilck;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	return (ilck->held);
 }
@@ -199,6 +203,7 @@ Lck__Owned(const struct lock *lck)
 {
 	struct ilck *ilck;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	AN(ilck->held);
 	return (pthread_equal(ilck->owner, pthread_self()));
@@ -211,6 +216,7 @@ Lck_CondWait(pthread_cond_t *cond, struct lock *lck, vtim_real when)
 	struct timespec ts;
 	vtim_real t;
 
+	AN(lck);
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	AN(ilck->held);
 	assert(pthread_equal(ilck->owner, pthread_self()));
@@ -254,6 +260,7 @@ Lck__New(struct lock *lck, struct VSC_lck *st, const char *w)
 
 	AN(st);
 	AN(w);
+	AN(lck);
 	AZ(lck->priv);
 	ALLOC_OBJ(ilck, ILCK_MAGIC);
 	AN(ilck);
@@ -269,6 +276,7 @@ Lck_Delete(struct lock *lck)
 {
 	struct ilck *ilck;
 
+	AN(lck);
 	TAKE_OBJ_NOTNULL(ilck, &lck->priv, ILCK_MAGIC);
 	ilck->stat->destroy++;
 	AZ(pthread_mutex_destroy(&ilck->mtx));


More information about the varnish-commit mailing list