瀏覽代碼

avoid possible null ref

UbitUmarov 6 天之前
父節點
當前提交
df4664f05b
共有 1 個文件被更改,包括 17 次插入7 次删除
  1. 17 7
      OpenSim/Addons/Groups/Service/GroupsService.cs

+ 17 - 7
OpenSim/Addons/Groups/Service/GroupsService.cs

@@ -1058,14 +1058,24 @@ namespace OpenSim.Groups
         private bool HasPower(string agentID, UUID groupID, GroupPowers power)
         {
             RoleMembershipData[] rmembership = m_Database.RetrieveMemberRoles(groupID, agentID);
-            if (rmembership == null || (rmembership != null && rmembership.Length == 0))
+            if (rmembership is null || rmembership.Length == 0)
                 return false;
 
             foreach (RoleMembershipData rdata in rmembership)
             {
+                if(rdata is null)
+                {
+                    m_log.Warn($"[GROUPSERVICE] null membership  data entry in group {groupID} for agent {agentID}");
+                    continue;
+                }
                 RoleData role = m_Database.RetrieveRole(groupID, rdata.RoleID);
-                if ( (UInt64.Parse(role.Data["Powers"]) & (ulong)power) != 0 )
-                    return true;
+                if (role is null)
+                {
+                    m_log.Warn($"[GROUPSERVICE] role with id {rdata.RoleID} is null");
+                    return false;
+                }
+
+                return (UInt64.Parse(role.Data["Powers"]) & (ulong)power) != 0;
             }
             return false;
         }
@@ -1073,14 +1083,14 @@ namespace OpenSim.Groups
         private bool IsOwner(string agentID, UUID groupID)
         {
             GroupData group = m_Database.RetrieveGroup(groupID);
-            if (group == null)
+            if (group is null)
                 return false;
 
-            RoleMembershipData rmembership = m_Database.RetrieveRoleMember(groupID, new UUID(group.Data["OwnerRoleID"]), agentID);
-            if (rmembership == null)
+            if(!UUID.TryParse(group.Data["OwnerRoleID"], out UUID ownerRoleID))
                 return false;
 
-            return true;
+            RoleMembershipData rmembership = m_Database.RetrieveRoleMember(groupID, ownerRoleID, agentID);
+            return rmembership is not null;
         }
         #endregion