cmd.exe bug / GetFileType from kernel mode
-
Okay... this question feels out of place in this forum, but it doesn't fit in OS/SysAdmin as that is more of the usage side - not the programming side. Given my driver is in C++, I figure this is as good a place as any. That out of the way, I found a bug (handle leak) in cmd.exe: I'm writing a device driver that I want to be able to write stuff to via the command prompt redirection. For example, typing
echo Hello there > \\.\MyDevice
Should send the string "Hello there" to the MyDevice device. Unfortunately it does not work. Cmd opens the handle to my device, but never writes to it or closes it! So until I exit cmd, my driver cannot be unloaded. Some debugging indicates that cmd opens my device with CreateFile, which succeeds, then calls GetFileType, and since it is not a file or network file, it cancels the redirection operation, forgetting to close the original handle. So now for the real question: Does anybody happen to know how GetFileType is implemented in kernel mode (ie. if there's a field of the FILE_OBJECT I can set to get GetFileType to work properly? Or is there any way to register something like
lpt1
which is a device that cmd can write to? Thanks, Mike