Skip to content

Commit

Permalink
Bunch of updates from Coverity run - mainly null references
Browse files Browse the repository at this point in the history
  • Loading branch information
greythane committed Aug 15, 2019
1 parent cf1b728 commit 648ca5d
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 113 deletions.
113 changes: 56 additions & 57 deletions WhiteCore/DataManagerPlugins/MySQL/MySQLDataManager.cs
Expand Up @@ -178,11 +178,11 @@ List<string> QueryFullData2(string query)
{
using (reader = Query(query, new Dictionary<string, object>()))
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
retVal.Add(reader.GetString(i));
if (reader != null) {
while (reader.Read ()) {
for (int i = 0; i < reader.FieldCount; i++) {
retVal.Add (reader.GetString (i));
}
}
}
return retVal;
Expand All @@ -191,7 +191,7 @@ List<string> QueryFullData2(string query)
catch (Exception e)
{
MainConsole.Instance.Error("[MySQL]: QueryFullData(" + query + "), " + e);
return null;
return new List<string>();
}
}

Expand Down Expand Up @@ -264,12 +264,12 @@ private IDataReader QueryData2(string query)
{
using (reader = Query(query, ps))
{
while (reader.Read())
{
for (i = 0; i < reader.FieldCount; i++)
{
Type r = reader[i].GetType();
retVal.Add(r == typeof (DBNull) ? null : reader.GetString(i));
if (reader != null) {
while (reader.Read ()) {
for (i = 0; i < reader.FieldCount; i++) {
Type r = reader [i].GetType ();
retVal.Add (r == typeof (DBNull) ? null : reader.GetString (i));
}
}
}
return retVal;
Expand Down Expand Up @@ -316,15 +316,14 @@ private IDataReader QueryData2(string query)

try
{
using (reader = Query(query, ps))
{
while (reader.Read())
{
for (i = 0; i < reader.FieldCount; i++)
{
Type r = reader[i].GetType();
AddValueToList(ref retVal, reader.GetName(i),
r == typeof (DBNull) ? null : reader[i].ToString());
using (reader = Query (query, ps)) {
if (reader != null) {
while (reader.Read ()) {
for (i = 0; i < reader.FieldCount; i++) {
Type r = reader [i].GetType ();
AddValueToList (ref retVal, reader.GetName (i),
r == typeof (DBNull) ? null : reader [i].ToString ());
}
}
}
return retVal;
Expand All @@ -333,7 +332,7 @@ private IDataReader QueryData2(string query)
catch (Exception e)
{
MainConsole.Instance.Error("[MySQL]: QueryNames(" + query + "), " + e);
return null;
return new Dictionary<string, List<string>>();
}
}

Expand Down Expand Up @@ -1025,11 +1024,11 @@ public override bool TableExists(string table)
{
using (reader = Query("show tables", new Dictionary<string, object>()))
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
retVal.Add(reader.GetString(i).ToLower());
if (reader != null) {
while (reader.Read ()) {
for (int i = 0; i < reader.FieldCount; i++) {
retVal.Add (reader.GetString (i).ToLower ());
}
}
}
}
Expand All @@ -1049,25 +1048,25 @@ protected override List<ColumnDefinition> ExtractColumnsFromTable(string tableNa
try
{
rdr = Query(string.Format("desc {0}", tableName), new Dictionary<string, object>());
while (rdr.Read())
{
var name = rdr["Field"];
//var pk = rdr["Key"];
var type = rdr["Type"];
//var extra = rdr["Extra"];
object defaultValue = rdr["Default"];

ColumnTypeDef typeDef = ConvertTypeToColumnType(type.ToString());
typeDef.isNull = rdr["Null"].ToString() == "YES";
typeDef.auto_increment = rdr ["Extra"].ToString ().IndexOf ("auto_increment", StringComparison.Ordinal) >= 0;
typeDef.defaultValue = defaultValue is DBNull
? null
: defaultValue.ToString ();
defs.Add(new ColumnDefinition
{
Name = name.ToString(),
Type = typeDef,
});
if (rdr != null) {
while (rdr.Read ()) {
var name = rdr ["Field"];
//var pk = rdr["Key"];
var type = rdr ["Type"];
//var extra = rdr["Extra"];
object defaultValue = rdr ["Default"];

ColumnTypeDef typeDef = ConvertTypeToColumnType (type.ToString ());
typeDef.isNull = rdr ["Null"].ToString () == "YES";
typeDef.auto_increment = rdr ["Extra"].ToString ().IndexOf ("auto_increment", StringComparison.Ordinal) >= 0;
typeDef.defaultValue = defaultValue is DBNull
? null
: defaultValue.ToString ();
defs.Add (new ColumnDefinition {
Name = name.ToString (),
Type = typeDef,
});
}
}
}
catch (Exception e)
Expand Down Expand Up @@ -1104,18 +1103,18 @@ protected override List<ColumnDefinition> ExtractColumnsFromTable(string tableNa
try
{
rdr = Query(string.Format("SHOW INDEX IN {0}", tableName), new Dictionary<string, object>());
while (rdr.Read())
{
string name = rdr["Column_name"].ToString();
bool unique = uint.Parse(rdr["Non_unique"].ToString()) == 0;
string index = rdr["Key_name"].ToString();
uint sequence = uint.Parse(rdr["Seq_in_index"].ToString());
if (!indexLookup.ContainsKey(index))
{
indexLookup[index] = new Dictionary<uint, string>();
if (rdr != null) {
while (rdr.Read ()) {
string name = rdr ["Column_name"].ToString ();
bool unique = uint.Parse (rdr ["Non_unique"].ToString ()) == 0;
string index = rdr ["Key_name"].ToString ();
uint sequence = uint.Parse (rdr ["Seq_in_index"].ToString ());
if (!indexLookup.ContainsKey (index)) {
indexLookup [index] = new Dictionary<uint, string> ();
}
indexIsUnique [index] = unique;
indexLookup [index] [sequence - 1] = name;
}
indexIsUnique[index] = unique;
indexLookup[index][sequence - 1] = name;
}
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion WhiteCore/Framework/Services/ConnectorBase.cs
Expand Up @@ -122,7 +122,7 @@ public void Init (IRegistryCore registry, string name, string password = "", str
m_OSDRequestTryCount = config.GetInt ("OSDRequestTryCount", m_OSDRequestTryCount);
}
if (m_doRemoteCalls)
m_doRemoteOnly = true; //Lock out local + remote for now
m_doRemoteOnly = true; // Lock out local + remote for now

ConnectorRegistry.RegisterConnector (this);

Expand Down
8 changes: 4 additions & 4 deletions WhiteCore/Modules/Avatar/GodModule/GodsModule.cs
Expand Up @@ -59,11 +59,11 @@ public class GodsModule : INonSharedRegionModule, IGodsModule
{
IScenePresence sp = m_scene.GetScenePresence (agentID);

// NPC's are not allowed
if (sp.IsNpcAgent)
return;

if (sp != null) {
// NPC's are not allowed
if (sp.IsNpcAgent)
return;

if (godLike == false) {
//Unconditionally remove god levels
sp.GodLevel = Constants.USER_NORMAL;
Expand Down
1 change: 1 addition & 0 deletions WhiteCore/Modules/Avatar/Groups/GroupMoneyModule.cs
Expand Up @@ -126,6 +126,7 @@ where h.Stipend
intervalDays,
Util.BuildYMDDateString (groupBalance.StartingDate.AddDays (-currentInterval * intervalDays)),
history.ToArray ());
groupBalance = null;
} else
client.SendGroupAccountingDetails (client, groupID, transactionID, sessionID, 0, currentInterval,
intervalDays,
Expand Down
6 changes: 5 additions & 1 deletion WhiteCore/Modules/Avatar/Groups/GroupsModule.cs
Expand Up @@ -597,7 +597,11 @@ public void EjectGroupMember (IClientAPI remoteClient, UUID agentID, UUID groupI
}
}

GroupRecord groupInfo = m_groupData.GetGroupRecord (GetRequestingAgentID (remoteClient), groupID, null);
GroupRecord groupInfo = null;
if ( remoteClient != null)
groupInfo = m_groupData.GetGroupRecord (GetRequestingAgentID (remoteClient), groupID, null);
else
groupInfo = m_groupData.GetGroupRecord (agentID, groupID, null);

UserAccount ejectAcct = m_scene.UserAccountService.GetUserAccount (regionInfo.AllScopeIDs, ejecteeID);

Expand Down
1 change: 1 addition & 0 deletions WhiteCore/Modules/Avatar/Profile/ProfileModule.cs
Expand Up @@ -702,6 +702,7 @@ public void TrackAgent (IClientAPI client, UUID hunter, UUID target)
if (region != null) // just being cautious here
client.SendScriptTeleportRequest (client.Name, region.RegionName,
GUI.CurrentPosition, GUI.CurrentLookAt);
region = null; // clean up
}
}
}
Expand Down
37 changes: 21 additions & 16 deletions WhiteCore/Modules/Currency/Base.CurrencyConnector.cs
Expand Up @@ -107,9 +107,10 @@ public string Name
[CanBeReflected(ThreatLevel = ThreatLevel.Low)]
public BaseCurrencyConfig GetConfig()
{
object remoteValue = DoRemoteByURL("CurrencyServerURI");
if (remoteValue != null || m_doRemoteOnly)
return (BaseCurrencyConfig) remoteValue;
if (m_doRemoteOnly) {
object remoteValue = DoRemoteByURL ("CurrencyServerURI");
return (remoteValue != null) ? (BaseCurrencyConfig)remoteValue : new BaseCurrencyConfig ();
}

return m_config;
}
Expand All @@ -119,9 +120,10 @@ public BaseCurrencyConfig GetConfig()
[CanBeReflected(ThreatLevel = ThreatLevel.Low)]
public GroupBalance GetGroupBalance(UUID groupID)
{
object remoteValue = DoRemoteByURL("CurrencyServerURI", groupID);
if (remoteValue != null || m_doRemoteOnly)
return (GroupBalance) remoteValue;
if (m_doRemoteOnly) {
object remoteValue = DoRemoteByURL ("CurrencyServerURI", groupID);
return (remoteValue != null) ? (GroupBalance)remoteValue : new GroupBalance ();
}

GroupBalance gb = new GroupBalance {
GroupFee = 0,
Expand Down Expand Up @@ -153,9 +155,10 @@ public GroupBalance GetGroupBalance(UUID groupID)
int currentInterval, int intervalDays)
{
//return new List<GroupAccountHistory>();
object remoteValue = DoRemoteByURL("CurrencyServerURI", groupID, fromAgentID, currentInterval, intervalDays);
if (remoteValue != null || m_doRemoteOnly)
return (List<GroupAccountHistory>) remoteValue;
if (m_doRemoteOnly) {
object remoteValue = DoRemoteByURL ("CurrencyServerURI", groupID, fromAgentID, currentInterval, intervalDays);
return (remoteValue != null) ? (List<GroupAccountHistory>)remoteValue : new List<GroupAccountHistory> ();
}

QueryFilter filter = new QueryFilter();

Expand Down Expand Up @@ -279,13 +282,15 @@ public GroupBalance GetGroupBalance(UUID groupID)
(groupInfo == null ? "" : groupName + " ") + InWorldCurrency + amount + paidDesc;
}

if (payUser) {
if (agentInfo != null && agentInfo.IsOnline) {
SendUpdateMoneyBalanceToClient (userId, transactionID, agentInfo.CurrentRegionURI, userBalance, paidToMsg);
}
} else {
if (fromObjectID != UUID.Zero) {
SendUpdateMoneyBalanceToClient (fromObjectID, transactionID, agentInfo.CurrentRegionURI, (uint) amount, paidFromMsg);
if (agentInfo != null) {
if (payUser) {
if (agentInfo.IsOnline) {
SendUpdateMoneyBalanceToClient (userId, transactionID, agentInfo.CurrentRegionURI, userBalance, paidToMsg);
}
} else {
if (fromObjectID != UUID.Zero) {
SendUpdateMoneyBalanceToClient (fromObjectID, transactionID, agentInfo.CurrentRegionURI, (uint)amount, paidFromMsg);
}
}
}
}
Expand Down
Expand Up @@ -476,7 +476,7 @@ public virtual bool TeleportHome (UUID id, IClientAPI client)
// Default region time...
List<GridRegion> defaultRegions = client.Scene.GridService.GetDefaultRegions (client.AllScopeIDs);
if (defaultRegions.Count > 0) {
MainConsole.Instance.DebugFormat ( "[Entity transfer]: User's home region was not found, using {0} {1} ({2}-{3})",
MainConsole.Instance.DebugFormat ("[Entity transfer]: User's home region was not found, using {0} {1} ({2}-{3})",
defaultRegions [0].RegionName,
defaultRegions [0].RegionID,
defaultRegions [0].RegionLocX / Constants.RegionSize,
Expand All @@ -486,6 +486,7 @@ public virtual bool TeleportHome (UUID id, IClientAPI client)
client, defaultRegions [0], new Vector3 (128, 128, 25), new Vector3 (128, 128, 128),
(uint)(TeleportFlags.SetLastToTarget | TeleportFlags.ViaHome));
} else
defaultRegions = null;
return false;
}

Expand Down
17 changes: 11 additions & 6 deletions WhiteCore/Modules/World/Estate/EstateManagementModule.cs
Expand Up @@ -401,7 +401,7 @@ enum AccessDeltaRequest
// EstateAccessDelta handles Estate Managers, Sim Access, Sim Banlist, allowed Groups.. etc.

if (user == m_scene.RegionInfo.EstateSettings.EstateOwner)
return; // never process EO
return; // never process Estate Owner

IEstateConnector connector = Framework.Utilities.DataManager.RequestPlugin<IEstateConnector> ();
List<EstateSettings> estates;
Expand Down Expand Up @@ -439,19 +439,24 @@ enum AccessDeltaRequest
actions.Add ((userID) =>
{
IScenePresence SP = m_scene.GetScenePresence (user);
var banhostEP = "0.0.0.0";
if (SP != null) {
var bIP = (System.Net.IPEndPoint)SP.ControllingClient.GetClientEP ();
if (bIP != null)
banhostEP = bIP.Address.ToString ();
}
EstateBan item = new EstateBan {
BannedUserID = userID,
EstateID = es.EstateID,
BannedHostAddress = "0.0.0.0",
BannedHostIPMask = (SP != null)
? ((System.Net.IPEndPoint)SP.ControllingClient.GetClientEP ()).Address.ToString ()
: "0.0.0.0"
BannedHostIPMask = banhostEP
};
es.AddBan (item);
IEntityTransferModule transferModule =
m_scene.RequestModuleInterface<IEntityTransferModule> ();
IEntityTransferModule transferModule = m_scene.RequestModuleInterface<IEntityTransferModule> ();
if (SP != null && transferModule != null)
{
if (!SP.IsChildAgent)
Expand Down

0 comments on commit 648ca5d

Please sign in to comment.