Browse Source

Bugfix: FormatException was thrown upon InvalidDataException in some cases

Tal Aloni 7 years ago
parent
commit
24a65d0a03

+ 1 - 1
SMBLibrary/NetBios/SessionPackets/SessionPacket.cs

@@ -81,7 +81,7 @@ namespace SMBLibrary.NetBios
                 case SessionPacketTypeName.SessionKeepAlive:
                     return new SessionKeepAlivePacket(buffer, offset);
                 default:
-                    throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + type.ToString("X2"));
+                    throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + ((byte)type).ToString("X2"));
             }
         }
     }

+ 2 - 2
SMBLibrary/SMB1/Commands/SMB1Command.cs

@@ -163,7 +163,7 @@ namespace SMBLibrary.SMB1
                 case CommandName.SMB_COM_NT_CANCEL:
                     return new NTCancelRequest(buffer, offset);
                 default:
-                    throw new InvalidDataException("Invalid SMB command 0x" + commandName.ToString("X2"));
+                    throw new InvalidDataException("Invalid SMB command 0x" + ((byte)commandName).ToString("X2"));
             }
         }
 
@@ -475,7 +475,7 @@ namespace SMBLibrary.SMB1
                         }
                     }
                 default:
-                    throw new InvalidDataException("Invalid SMB command 0x" + commandName.ToString("X2"));
+                    throw new InvalidDataException("Invalid SMB command 0x" + ((byte)commandName).ToString("X2"));
             }
         }
 

+ 2 - 2
SMBLibrary/SMB2/Commands/SMB2Command.cs

@@ -104,7 +104,7 @@ namespace SMBLibrary.SMB2
                 case SMB2CommandName.SetInfo:
                     return new SetInfoRequest(buffer, offset);
                 default:
-                    throw new InvalidDataException("Invalid SMB2 command 0x" + commandName.ToString("X4"));
+                    throw new InvalidDataException("Invalid SMB2 command 0x" + ((ushort)commandName).ToString("X4"));
             }
         }
 
@@ -471,7 +471,7 @@ namespace SMBLibrary.SMB2
                         }
                     }
                 default:
-                    throw new InvalidDataException("Invalid SMB2 command 0x" + commandName.ToString("X4"));
+                    throw new InvalidDataException("Invalid SMB2 command 0x" + ((ushort)commandName).ToString("X4"));
             }
         }