aboutsummaryrefslogtreecommitdiff
path: root/src/net_permissions.h
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-04-14 17:10:28 +0200
committerJon Atack <jon@atack.com>2021-04-18 16:32:28 +0200
commit36fb036d25e2a3016b36873456e5a9e6251ffef8 (patch)
treebacfb98e3b05210ae2beebe091c14c12274ee7ba /src/net_permissions.h
parent4e0d5788ba5771c81bc0ff2e6523cf9accddae46 (diff)
p2p: allow NetPermissions::ClearFlag() only with PF_ISIMPLICIT
NetPermissions::ClearFlag() is currently only called in the codebase with an `f` value of NetPermissionFlags::PF_ISIMPLICIT. If that should change in the future, ClearFlag() should not be called with `f` being a subflag of a multiflag, e.g. NetPermissionFlags::PF_RELAY or NetPermissionFlags::PF_DOWNLOAD, as that would leave `flags` in an invalid state corresponding to none of the existing NetPermissionFlags. Therefore, allow only calling ClearFlag with the implicit flag for now. Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Diffstat (limited to 'src/net_permissions.h')
-rw-r--r--src/net_permissions.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/net_permissions.h b/src/net_permissions.h
index bba0ea1695..142b317bf6 100644
--- a/src/net_permissions.h
+++ b/src/net_permissions.h
@@ -51,8 +51,14 @@ public:
{
flags = static_cast<NetPermissionFlags>(flags | f);
}
+ //! ClearFlag is only called with `f` == NetPermissionFlags::PF_ISIMPLICIT.
+ //! If that should change in the future, be aware that ClearFlag should not
+ //! be called with a subflag of a multiflag, e.g. NetPermissionFlags::PF_RELAY
+ //! or NetPermissionFlags::PF_DOWNLOAD, as that would leave `flags` in an
+ //! invalid state corresponding to none of the existing flags.
static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
{
+ assert(f == NetPermissionFlags::PF_ISIMPLICIT);
flags = static_cast<NetPermissionFlags>(flags & ~f);
}
};