This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: [PATCH] QueryDosDevice in handle_to_fn
On Sun, Mar 16, 2008 at 04:22:13PM +0100, Corinna Vinschen wrote:
>On Mar 16 03:14, Brian Dessent wrote:
>> I debugged this and found the
>> strangest thing, when you call QueryDosDevice (NULL, fnbuf, len) to get
>> the list of all DOS devices and len >= 65536, Win32 always returns 0
>> with GetLastError set to ERROR_MORE_DATA. Since len was being set as
>> "sizeof (OBJECT_NAME_INFORMATION) + NT_MAX_PATH * sizeof (WCHAR)" this
>> always happened, causing handle_to_fn() to simply give up and copy the
>> Win32 name into the POSIX name and return. The attached patch fixes the
>> problem by just clamping the size of the buffer to under 64k.
>
><insert lament here>
>
>> Another observation that I had while debugging this is that calling
>> strncasematch() in this function is probably wrong -- it expands to
>> cygwin_strncasecmp(), which is a wrapper that first converts both
>> arguments to temporary UNICODE strings and then calls
>> RtlCompareUnicodeString() -- we're doing this on strings that we had
>> just converted *out* of UNICODE. I think ascii_strncasematch() is
>> probably what we want here instead, either that or try to stay in
>> unicode throughout.
>
>Using ascii_strncasematch here is right because the DEVICE_PREFIX is
>plain ascii anyway. But, yes, the function should be converted to
>do everything in WCHAR/UNICODE_STRING and only convert to char *
>when creating the final posix_fn.
>
>> + /* For some reason QueryDosDevice will fail with Win32 errno 234
>> + (ERROR_MORE_DATA) if you try to pass a buffer larger than 64k */
>> + size_t qddlen = len < 65536 ? len : 65535;
>
>len is a const value. Checking len for being < 65536 is a constant
>expression which always results in qddlen being 65535 so the ?: is
>a noop, more or less.
>
>Did you test if QueryDosDeviceW has the same problem as QueryDosDeviceA?
>If not, we should use that function.
This is basically my function. I'll try to convert it to use Unicode
today.
cgf