Patchwork [1,of,2] win32: allocate buffer of maximum length for GetVolumeInformation()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 2, 2018, 3:40 a.m.
Message ID <99cf3126c685bebbac8e.1514864443@mimosa>
Download mbox | patch
Permalink /patch/26516/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 2, 2018, 3:40 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1514862145 -32400
#      Tue Jan 02 12:02:25 2018 +0900
# Node ID 99cf3126c685bebbac8e7048f9267494d67ead50
# Parent  e01549a7bf0a6a7adbbb317a5d4bfde36c205b4d
win32: allocate buffer of maximum length for GetVolumeInformation()

It's documented that "the maximum buffer size is MAX_PATH+1", which is
slightly larger than 256.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx

Patch

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 import ctypes
+import ctypes.wintypes as wintypes
 import errno
 import msvcrt
 import os
@@ -33,6 +34,7 @@  from . import (
 _HANDLE = ctypes.c_void_p
 _HWND = _HANDLE
 _PCCERT_CONTEXT = ctypes.c_void_p
+_MAX_PATH = wintypes.MAX_PATH
 
 _INVALID_HANDLE_VALUE = _HANDLE(-1).value
 
@@ -460,7 +462,7 @@  def getfstype(path):
                    _DRIVE_RAMDISK):
         return None
 
-    size = 256
+    size = _MAX_PATH + 1
     name = ctypes.create_string_buffer(size)
 
     if not _kernel32.GetVolumeInformationA(volume, None, 0, None, None, None,