|
Cross Your Ts and Dot Your Filenames
I was developing some automation code recently and found that a process that I was injecting code into was crashing. At first I thought it was an error in my injected code, but when I looked at the crash-dump, I was amazed to see that the issue was in MFC42.DLL:
The code above is from MFC42.DLL, version 6.2.4131.0 from Windows XP SP2. It effectively does the following:
The function _mbsrchr(...) returns NULL if the character searched for is not found. This means that if there is no . in the current processs filename (which was the case for the file I was testing) then the highlighted line above will try to write the byte 0x00 to address 0x00000000, which will cause a crash. I figured that this was some obscure function from MFC42.DLL that most applications dont make use of, however, after a little digging it turns out that this code is in CWinApp::SetCurrentHandles(), which is called by AfxWinInit(...). From http://msdn2.microsoft.com/en-us/library/w04bs753(vs.80).aspx:
In other words, almost every MFC GUI program executes the code snippet above! AAs surprised as I was by this, I figured that surely this had been fixed for Vista. Believe it or not, the same issue exists! Below is the code from MFC42.DLL version 6.6.8063.0 from Windows Vista Gold:
While the code above checks for the lack of a . in the filename, it still throws an exception and causes a crash if theres no .. The good news is that it doesnt seem easy to accidentally execute an executable file without a . in the filename in Vista:
However, it is still possible to run non-dotted-files via API functions like CreateProcess(...) to cause the crash described above. Comments
| ||||||