Client: Fix possible NullReferenceException when disconnection occur during directory enumeration

This commit is contained in:
Tal Aloni 2024-06-12 12:20:04 +03:00
parent a2b96f638c
commit aeb8849683
2 changed files with 11 additions and 3 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2014-2023 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -181,7 +181,11 @@ namespace SMBLibrary.Client
TrySendMessage(request); TrySendMessage(request);
reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2); reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response) if (reply == null)
{
return NTStatus.STATUS_INVALID_SMB;
}
else if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
{ {
response = (Transaction2Response)reply.Commands[0]; response = (Transaction2Response)reply.Commands[0];
Transaction2FindNext2Response nextSubcommandResponse = new Transaction2FindNext2Response(response.TransParameters, response.TransData, reply.Header.UnicodeFlag); Transaction2FindNext2Response nextSubcommandResponse = new Transaction2FindNext2Response(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2017-2023 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2017-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -165,6 +165,10 @@ namespace SMBLibrary.Client
request.Reopen = false; request.Reopen = false;
TrySendCommand(request); TrySendCommand(request);
response = m_client.WaitForCommand(request.MessageID); response = m_client.WaitForCommand(request.MessageID);
if (response == null)
{
return NTStatus.STATUS_INVALID_SMB;
}
} }
return response.Header.Status; return response.Header.Status;
} }