-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
use correct path lengths #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
use correct path lengths #1937
Conversation
volumeNameBufferLength = uint32(windows.MAX_PATH + 1) | ||
volumePathBufferLength = volumeNameBufferLength | ||
maxWarningsInDrive = 5 | ||
maxVolumeNameLength = uint32(windows.MAX_PATH + 1) // this should be a GUID (50), but for safety I keep max_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a guid in string format that represent the volume, as far as I know all volumes are in guid format, but it's not well specified in documentation, so I keep MAX_PATH in case a volume can have a name in a longer format.
return partitionStats, err | ||
} | ||
drivesString := windows.UTF16ToString(lpBuffer) | ||
drives := strings.Split(drivesString, "\x00") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all drive names are separated by an UTF-16 null character
uintptr(0), | ||
uintptr(0)) | ||
|
||
lpBuffer := make([]uint16, bufferLen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixes the call when you have many drives mounted and a buffer > windows.MAX_PATH
uintptr(len(volumeName)), | ||
uintptr(unsafe.Pointer(&serialNumber)), | ||
uintptr(unsafe.Pointer(&maxComponentLength)), | ||
uintptr(0), // serial numbrt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these data are not used, so it's better to don't request them
return nil, fmt.Errorf("failed to get volume paths size for volume %s: %w", windows.UTF16ToString(volNameBuf), volumePathFirstErr) | ||
} | ||
|
||
volPathsBuf := make([]uint16, returnLen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixes the call when a volume is mounted as a folder in a path longer than 256 characters
Fix to use correct paths/buffer lengths, consider that NTFS supports also paths longer than 256 (windows.MAX_PATH)