From b265b74be2ae8652e3098809a29743dc0c903a56 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 1 Apr 2024 10:38:06 +1030 Subject: [PATCH] Prevent client code accessing defaultHandler mutex The embedding of the mutex allows client code to call all the methods on it. This should probably not be allowed, so unembed as an unexported field. --- default_handler.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/default_handler.go b/default_handler.go index 3da16b1e..73eab8f5 100644 --- a/default_handler.go +++ b/default_handler.go @@ -33,7 +33,7 @@ func NewDefaultHandler() *defaultHandler { } type defaultHandler struct { - sync.RWMutex + mu sync.RWMutex objects map[ObjectPath]*exportedObj defaultIntf map[string]*exportedIntf } @@ -65,8 +65,8 @@ func (h *defaultHandler) introspectPath(path ObjectPath) string { } func (h *defaultHandler) LookupObject(path ObjectPath) (ServerObject, bool) { - h.RLock() - defer h.RUnlock() + h.mu.RLock() + defer h.mu.RUnlock() object, ok := h.objects[path] if ok { return object, ok @@ -102,15 +102,15 @@ func (h *defaultHandler) LookupObject(path ObjectPath) (ServerObject, bool) { } func (h *defaultHandler) AddObject(path ObjectPath, object *exportedObj) { - h.Lock() + h.mu.Lock() h.objects[path] = object - h.Unlock() + h.mu.Unlock() } func (h *defaultHandler) DeleteObject(path ObjectPath) { - h.Lock() + h.mu.Lock() delete(h.objects, path) - h.Unlock() + h.mu.Unlock() } type exportedMethod struct {