From b0a6540bdc7661911c592274ef1e4b367adcad87 Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Fri, 3 Feb 2023 16:07:11 -0300 Subject: [PATCH 1/3] Fix Null Dereference and Privacy Violation issues. --- .../DynServiceFabric/FabricConnection.cs | 33 ++++++++++--------- .../GxClasses/Data/GXDataMysqlDriverCS.cs | 1 - 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dotnet/src/dotnetframework/DynServiceFabric/FabricConnection.cs b/dotnet/src/dotnetframework/DynServiceFabric/FabricConnection.cs index 6be7c9970..6ce703d24 100644 --- a/dotnet/src/dotnetframework/DynServiceFabric/FabricConnection.cs +++ b/dotnet/src/dotnetframework/DynServiceFabric/FabricConnection.cs @@ -36,30 +36,31 @@ bool SetServiceData(string connStr, GxHttpClient restClient) { DbConnectionStringBuilder builder = new DbConnectionStringBuilder(false); builder.ConnectionString = connStr; - object serviceUri = ""; - object userID = ""; - object password = ""; + object userID; if (builder.TryGetValue("User Id", out userID)) { + object password; if (builder.TryGetValue("Password", out password)) { restClient.AddAuthentication(0, "", userID.ToString(), password.ToString()); } } - object ds_data = ""; - object uri_data = ""; + + object ds_data; + object uri_data; + object serviceUri; if (builder.TryGetValue("Data Source", out ds_data)) serviceUri = ds_data; else if (builder.TryGetValue("uri", out uri_data)) - serviceUri = uri_data; - else - serviceUri = null; + serviceUri = uri_data; + else + serviceUri = null; if (serviceUri != null) { - String urlstring = ""; String[] parts = serviceUri.ToString().Split(new String[] { "://" }, StringSplitOptions.None); + string urlstring; if (parts.Length > 1) { if (parts[0].Equals("https")) @@ -126,13 +127,13 @@ public override int ExecuteNonQuery(ServiceCursorDef cursorDef, IDataParameterCo } else { - throw new GxADODataException("Error executing: " + restClient.ToString()); + throw new GxADODataException("Error executing: " + restClient.ErrCode +":" + restClient.ErrDescription); } } } else { - throw new GxADODataException("Error connecting : " + this.ConnectionString ); + throw new GxADODataException("Error connecting : " + restClient.Url); } } else @@ -154,10 +155,10 @@ private bool processError(short code, string msg, out int statusCode, out strin try { dynamic dynresponse = jss.Deserialize(msg, queryresponse.GetType()); - var resultdata = (dynresponse as Dictionary)["error"]; - if (resultdata != null) + object resultdata = (dynresponse as Dictionary)["error"]; + String resultmessage = resultdata as String; + if (resultmessage != null) { - String resultmessage = resultdata as String; if (resultmessage.Contains("101")) { statusCode = 101; @@ -206,7 +207,7 @@ public override IDataReader ExecuteReader(ServiceCursorDef cursorDef, IDataParam FabricDataReader reader = null; DataStoreHelperFabric.Query query = cursorDef.Query as DataStoreHelperFabric.Query; payLoad.Clear(); - if (query.Filters.Length == 0) + if (query!=null && query.Filters.Length == 0) { Dictionary tempParms = new Dictionary(); foreach (KeyValuePair kvp in query.Parms) @@ -349,7 +350,7 @@ FabricDataReader runFabricQuery(DataStoreHelperFabric.Query query, Dictionary 1) { if (parts[0].Equals("https")) @@ -127,13 +126,13 @@ public override int ExecuteNonQuery(ServiceCursorDef cursorDef, IDataParameterCo } else { - throw new GxADODataException("Error executing: " + restClient.ErrCode +":" + restClient.ErrDescription); + throw new GxADODataException("Error executing: " + restClient.ToString()); } } } else { - throw new GxADODataException("Error connecting : " + restClient.Url); + throw new GxADODataException("Error connecting : " + this.ConnectionString ); } } else @@ -155,10 +154,10 @@ private bool processError(short code, string msg, out int statusCode, out strin try { dynamic dynresponse = jss.Deserialize(msg, queryresponse.GetType()); - object resultdata = (dynresponse as Dictionary)["error"]; - String resultmessage = resultdata as String; - if (resultmessage != null) + var resultdata = (dynresponse as Dictionary)["error"]; + if (resultdata != null) { + String resultmessage = resultdata as String; if (resultmessage.Contains("101")) { statusCode = 101; @@ -207,7 +206,7 @@ public override IDataReader ExecuteReader(ServiceCursorDef cursorDef, IDataParam FabricDataReader reader = null; DataStoreHelperFabric.Query query = cursorDef.Query as DataStoreHelperFabric.Query; payLoad.Clear(); - if (query!=null && query.Filters.Length == 0) + if (query.Filters.Length == 0) { Dictionary tempParms = new Dictionary(); foreach (KeyValuePair kvp in query.Parms) @@ -350,7 +349,7 @@ FabricDataReader runFabricQuery(DataStoreHelperFabric.Query query, Dictionary