github-advanced-security[bot] commented on code in PR #3072:
URL: https://github.com/apache/avro/pull/3072#discussion_r1707787483
##########
lang/csharp/src/apache/main/Specific/ObjectCreator.cs:
##########
@@ -201,87 +248,88 @@
/// </exception>
public Type GetType(Schema schema)
{
- switch(schema.Tag) {
- case Schema.Type.Null:
- break;
- case Schema.Type.Boolean:
- return typeof(bool);
- case Schema.Type.Int:
- return typeof(int);
- case Schema.Type.Long:
- return typeof(long);
- case Schema.Type.Float:
- return typeof(float);
- case Schema.Type.Double:
- return typeof(double);
- case Schema.Type.Bytes:
- return typeof(byte[]);
- case Schema.Type.String:
- return typeof(string);
- case Schema.Type.Union:
- {
- if (schema is UnionSchema unSchema && unSchema.Count == 2)
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ break;
+ case Schema.Type.Boolean:
+ return typeof(bool);
+ case Schema.Type.Int:
+ return typeof(int);
+ case Schema.Type.Long:
+ return typeof(long);
+ case Schema.Type.Float:
+ return typeof(float);
+ case Schema.Type.Double:
+ return typeof(double);
+ case Schema.Type.Bytes:
+ return typeof(byte[]);
+ case Schema.Type.String:
+ return typeof(string);
+ case Schema.Type.Union:
{
- Schema s1 = unSchema.Schemas[0];
- Schema s2 = unSchema.Schemas[1];
-
- // Nullable ?
- Type itemType = null;
- if (s1.Tag == Schema.Type.Null)
+ if (schema is UnionSchema unSchema && unSchema.Count
== 2)
{
- itemType = GetType(s2);
- }
- else if (s2.Tag == Schema.Type.Null)
- {
- itemType = GetType(s1);
- }
+ Schema s1 = unSchema.Schemas[0];
+ Schema s2 = unSchema.Schemas[1];
- if (itemType != null)
- {
- if (itemType.IsValueType && !itemType.IsEnum)
+ // Nullable ?
+ Type itemType = null;
+ if (s1.Tag == Schema.Type.Null)
{
- try
- {
- return
GenericNullableType.MakeGenericType(itemType);
- }
- catch
+ itemType = GetType(s2);
+ }
+ else if (s2.Tag == Schema.Type.Null)
+ {
+ itemType = GetType(s1);
+ }
+
+ if (itemType != null)
+ {
+ if (itemType.IsValueType && !itemType.IsEnum)
{
+ try
+ {
+ return
GenericNullableType.MakeGenericType(itemType);
+ }
+ catch
+ {
+ }
}
- }
- return itemType;
+ return itemType;
+ }
}
- }
- return typeof(object);
- }
- case Schema.Type.Array:
- {
- ArraySchema arrSchema = schema as ArraySchema;
- Type itemSchema = GetType(arrSchema.ItemSchema);
-
- return GenericListType.MakeGenericType(itemSchema);
- }
- case Schema.Type.Map:
- {
- MapSchema mapSchema = schema as MapSchema;
- Type itemSchema = GetType(mapSchema.ValueSchema);
+ return typeof(object);
+ }
+ case Schema.Type.Array:
+ {
+ ArraySchema arrSchema = schema as ArraySchema;
+ Type itemSchema = GetType(arrSchema.ItemSchema);
- return GenericMapType.MakeGenericType(typeof(string),
itemSchema );
- }
- case Schema.Type.Enumeration:
- case Schema.Type.Record:
- case Schema.Type.Fixed:
- case Schema.Type.Error:
- {
- // Should all be named types
- if (schema is NamedSchema named)
+ return GenericListType.MakeGenericType(itemSchema);
+ }
+ case Schema.Type.Map:
{
- return FindType(named.Fullname);
+ MapSchema mapSchema = schema as MapSchema;
+ Type itemSchema = GetType(mapSchema.ValueSchema);
Review Comment:
## Dereferenced variable may be null
Variable [mapSchema](1) may be null at this access because of [this](2)
assignment.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2345)
##########
lang/csharp/src/apache/main/Specific/ObjectCreator.cs:
##########
@@ -201,87 +248,88 @@
/// </exception>
public Type GetType(Schema schema)
{
- switch(schema.Tag) {
- case Schema.Type.Null:
- break;
- case Schema.Type.Boolean:
- return typeof(bool);
- case Schema.Type.Int:
- return typeof(int);
- case Schema.Type.Long:
- return typeof(long);
- case Schema.Type.Float:
- return typeof(float);
- case Schema.Type.Double:
- return typeof(double);
- case Schema.Type.Bytes:
- return typeof(byte[]);
- case Schema.Type.String:
- return typeof(string);
- case Schema.Type.Union:
- {
- if (schema is UnionSchema unSchema && unSchema.Count == 2)
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ break;
+ case Schema.Type.Boolean:
+ return typeof(bool);
+ case Schema.Type.Int:
+ return typeof(int);
+ case Schema.Type.Long:
+ return typeof(long);
+ case Schema.Type.Float:
+ return typeof(float);
+ case Schema.Type.Double:
+ return typeof(double);
+ case Schema.Type.Bytes:
+ return typeof(byte[]);
+ case Schema.Type.String:
+ return typeof(string);
+ case Schema.Type.Union:
{
- Schema s1 = unSchema.Schemas[0];
- Schema s2 = unSchema.Schemas[1];
-
- // Nullable ?
- Type itemType = null;
- if (s1.Tag == Schema.Type.Null)
+ if (schema is UnionSchema unSchema && unSchema.Count
== 2)
{
- itemType = GetType(s2);
- }
- else if (s2.Tag == Schema.Type.Null)
- {
- itemType = GetType(s1);
- }
+ Schema s1 = unSchema.Schemas[0];
+ Schema s2 = unSchema.Schemas[1];
- if (itemType != null)
- {
- if (itemType.IsValueType && !itemType.IsEnum)
+ // Nullable ?
+ Type itemType = null;
+ if (s1.Tag == Schema.Type.Null)
{
- try
- {
- return
GenericNullableType.MakeGenericType(itemType);
- }
- catch
+ itemType = GetType(s2);
+ }
+ else if (s2.Tag == Schema.Type.Null)
+ {
+ itemType = GetType(s1);
+ }
+
+ if (itemType != null)
+ {
+ if (itemType.IsValueType && !itemType.IsEnum)
{
+ try
+ {
+ return
GenericNullableType.MakeGenericType(itemType);
+ }
+ catch
+ {
+ }
Review Comment:
## Generic catch clause
Generic catch clause.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2352)
##########
lang/csharp/src/apache/main/Specific/ObjectCreator.cs:
##########
@@ -201,87 +248,88 @@
/// </exception>
public Type GetType(Schema schema)
{
- switch(schema.Tag) {
- case Schema.Type.Null:
- break;
- case Schema.Type.Boolean:
- return typeof(bool);
- case Schema.Type.Int:
- return typeof(int);
- case Schema.Type.Long:
- return typeof(long);
- case Schema.Type.Float:
- return typeof(float);
- case Schema.Type.Double:
- return typeof(double);
- case Schema.Type.Bytes:
- return typeof(byte[]);
- case Schema.Type.String:
- return typeof(string);
- case Schema.Type.Union:
- {
- if (schema is UnionSchema unSchema && unSchema.Count == 2)
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ break;
+ case Schema.Type.Boolean:
+ return typeof(bool);
+ case Schema.Type.Int:
+ return typeof(int);
+ case Schema.Type.Long:
+ return typeof(long);
+ case Schema.Type.Float:
+ return typeof(float);
+ case Schema.Type.Double:
+ return typeof(double);
+ case Schema.Type.Bytes:
+ return typeof(byte[]);
+ case Schema.Type.String:
+ return typeof(string);
+ case Schema.Type.Union:
{
- Schema s1 = unSchema.Schemas[0];
- Schema s2 = unSchema.Schemas[1];
-
- // Nullable ?
- Type itemType = null;
- if (s1.Tag == Schema.Type.Null)
+ if (schema is UnionSchema unSchema && unSchema.Count
== 2)
{
- itemType = GetType(s2);
- }
- else if (s2.Tag == Schema.Type.Null)
- {
- itemType = GetType(s1);
- }
+ Schema s1 = unSchema.Schemas[0];
+ Schema s2 = unSchema.Schemas[1];
- if (itemType != null)
- {
- if (itemType.IsValueType && !itemType.IsEnum)
+ // Nullable ?
+ Type itemType = null;
+ if (s1.Tag == Schema.Type.Null)
{
- try
- {
- return
GenericNullableType.MakeGenericType(itemType);
- }
- catch
+ itemType = GetType(s2);
+ }
+ else if (s2.Tag == Schema.Type.Null)
+ {
+ itemType = GetType(s1);
+ }
+
+ if (itemType != null)
+ {
+ if (itemType.IsValueType && !itemType.IsEnum)
{
+ try
+ {
+ return
GenericNullableType.MakeGenericType(itemType);
+ }
+ catch
+ {
+ }
}
- }
- return itemType;
+ return itemType;
+ }
}
- }
- return typeof(object);
- }
- case Schema.Type.Array:
- {
- ArraySchema arrSchema = schema as ArraySchema;
- Type itemSchema = GetType(arrSchema.ItemSchema);
-
- return GenericListType.MakeGenericType(itemSchema);
- }
- case Schema.Type.Map:
- {
- MapSchema mapSchema = schema as MapSchema;
- Type itemSchema = GetType(mapSchema.ValueSchema);
+ return typeof(object);
+ }
+ case Schema.Type.Array:
+ {
+ ArraySchema arrSchema = schema as ArraySchema;
+ Type itemSchema = GetType(arrSchema.ItemSchema);
Review Comment:
## Dereferenced variable may be null
Variable [arrSchema](1) may be null at this access because of [this](2)
assignment.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2344)
##########
lang/csharp/src/apache/main/Specific/ObjectCreator.cs:
##########
@@ -201,87 +248,88 @@
/// </exception>
public Type GetType(Schema schema)
{
- switch(schema.Tag) {
- case Schema.Type.Null:
- break;
- case Schema.Type.Boolean:
- return typeof(bool);
- case Schema.Type.Int:
- return typeof(int);
- case Schema.Type.Long:
- return typeof(long);
- case Schema.Type.Float:
- return typeof(float);
- case Schema.Type.Double:
- return typeof(double);
- case Schema.Type.Bytes:
- return typeof(byte[]);
- case Schema.Type.String:
- return typeof(string);
- case Schema.Type.Union:
- {
- if (schema is UnionSchema unSchema && unSchema.Count == 2)
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ break;
+ case Schema.Type.Boolean:
+ return typeof(bool);
+ case Schema.Type.Int:
+ return typeof(int);
+ case Schema.Type.Long:
+ return typeof(long);
+ case Schema.Type.Float:
+ return typeof(float);
+ case Schema.Type.Double:
+ return typeof(double);
+ case Schema.Type.Bytes:
+ return typeof(byte[]);
+ case Schema.Type.String:
+ return typeof(string);
+ case Schema.Type.Union:
{
- Schema s1 = unSchema.Schemas[0];
- Schema s2 = unSchema.Schemas[1];
-
- // Nullable ?
- Type itemType = null;
- if (s1.Tag == Schema.Type.Null)
+ if (schema is UnionSchema unSchema && unSchema.Count
== 2)
{
- itemType = GetType(s2);
- }
- else if (s2.Tag == Schema.Type.Null)
- {
- itemType = GetType(s1);
- }
+ Schema s1 = unSchema.Schemas[0];
+ Schema s2 = unSchema.Schemas[1];
- if (itemType != null)
- {
- if (itemType.IsValueType && !itemType.IsEnum)
+ // Nullable ?
+ Type itemType = null;
+ if (s1.Tag == Schema.Type.Null)
{
- try
- {
- return
GenericNullableType.MakeGenericType(itemType);
- }
- catch
+ itemType = GetType(s2);
+ }
+ else if (s2.Tag == Schema.Type.Null)
+ {
+ itemType = GetType(s1);
+ }
+
+ if (itemType != null)
+ {
+ if (itemType.IsValueType && !itemType.IsEnum)
{
+ try
+ {
+ return
GenericNullableType.MakeGenericType(itemType);
+ }
+ catch
+ {
+ }
Review Comment:
## Poor error handling: empty catch block
Poor error handling: empty catch block.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2349)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]