Skip to content

Commit

Permalink
fix NextEntryOffset for large directory listings (#1587)
Browse files Browse the repository at this point in the history
Co-authored-by: robn-applaton <[email protected]>
  • Loading branch information
robnanola and robn-applaton authored Sep 14, 2023
1 parent ddfd9d4 commit 6a3ecf7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions impacket/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,20 @@ def smb2QueryDirectory(connId, smbServer, recvPacket):
lenData = len(data)
padLen = (8 - (lenData % 8)) % 8

# For larger directory we might reach the OutputBufferLength so we need to set
# the NextEntryOffset to 0 for the last entry the will fit the buffer
try:
# Check if the next data will exceed the OutputBufferLength
nextData = searchResult[nItem + 1].getData()
lenNextData = len(nextData)
nextTotalData = totalData + lenData + padLen + lenNextData
if nextTotalData >= queryDirectoryRequest['OutputBufferLength']:
# Set the NextEntryOffset to 0 and get the data again
searchResult[nItem]['NextEntryOffset'] = 0
data = searchResult[nItem].getData()
except IndexError:
pass

if (totalData + lenData) >= queryDirectoryRequest['OutputBufferLength']:
connData['OpenedFiles'][fileID]['Open']['EnumerationLocation'] -= 1
break
Expand Down

0 comments on commit 6a3ecf7

Please sign in to comment.