diff --git a/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs b/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs index 6086725..bc91cf2 100644 --- a/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs +++ b/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs @@ -171,6 +171,12 @@ namespace SMBLibrary.Server.SMB1 state.LogToServer(Severity.Information, "GetFileSystemInformation on '{0}' succeeded. Information level: {1}", share.Name, subcommand.QueryFSInformationLevel); response.SetQueryFSInformation(queryFSInformation, header.UnicodeFlag); } + + if (response.InformationBytes.Length > maxDataCount) + { + header.Status = NTStatus.STATUS_BUFFER_OVERFLOW; + response.InformationBytes = ByteReader.ReadBytes(response.InformationBytes, 0, (int)maxDataCount); + } return response; } @@ -275,6 +281,12 @@ namespace SMBLibrary.Server.SMB1 state.LogToServer(Severity.Information, "GetFileInformation on '{0}{1}' succeeded. Information level: {2}", share.Name, path, subcommand.QueryInformationLevel); response.SetQueryInformation(queryInformation); } + + if (response.InformationBytes.Length > maxDataCount) + { + header.Status = NTStatus.STATUS_BUFFER_OVERFLOW; + response.InformationBytes = ByteReader.ReadBytes(response.InformationBytes, 0, (int)maxDataCount); + } return response; } @@ -331,6 +343,12 @@ namespace SMBLibrary.Server.SMB1 state.LogToServer(Severity.Information, "GetFileInformation on '{0}{1}' succeeded. Information level: {2}. (FID: {3})", share.Name, openFile.Path, subcommand.QueryInformationLevel, subcommand.FID); response.SetQueryInformation(queryInformation); } + + if (response.InformationBytes.Length > maxDataCount) + { + header.Status = NTStatus.STATUS_BUFFER_OVERFLOW; + response.InformationBytes = ByteReader.ReadBytes(response.InformationBytes, 0, (int)maxDataCount); + } return response; } diff --git a/SMBLibrary/Server/SMB2/QueryInfoHelper.cs b/SMBLibrary/Server/SMB2/QueryInfoHelper.cs index 7704764..92b721a 100644 --- a/SMBLibrary/Server/SMB2/QueryInfoHelper.cs +++ b/SMBLibrary/Server/SMB2/QueryInfoHelper.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Tal Aloni . All rights reserved. +/* Copyright (C) 2017-2019 Tal Aloni . All rights reserved. * * 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, @@ -46,6 +46,11 @@ namespace SMBLibrary.Server.SMB2 state.LogToServer(Severity.Information, "GetFileInformation on '{0}{1}' succeeded. Information class: {2}. (FileId: {3})", share.Name, openFile.Path, request.FileInformationClass, request.FileId.Volatile); QueryInfoResponse response = new QueryInfoResponse(); response.SetFileInformation(fileInformation); + if (response.OutputBuffer.Length > request.OutputBufferLength) + { + response.Header.Status = NTStatus.STATUS_BUFFER_OVERFLOW; + response.OutputBuffer = ByteReader.ReadBytes(response.OutputBuffer, 0, (int)request.OutputBufferLength); + } return response; } else if (request.InfoType == InfoType.FileSystem) @@ -69,6 +74,12 @@ namespace SMBLibrary.Server.SMB2 state.LogToServer(Severity.Information, "GetFileSystemInformation on '{0}' succeeded. Information class: {1}", share.Name, request.FileSystemInformationClass); QueryInfoResponse response = new QueryInfoResponse(); response.SetFileSystemInformation(fileSystemInformation); + if (response.OutputBuffer.Length > request.OutputBufferLength) + { + response.Header.Status = NTStatus.STATUS_BUFFER_OVERFLOW; + response.OutputBuffer = ByteReader.ReadBytes(response.OutputBuffer, 0, (int)request.OutputBufferLength); + } + return response; } }