IIS 7 and Above
ISAPI and parameter passing
Last post 1 hour, 34 minutes ago by DevPreSupport_MSFT
Oct 08, 2018 12:53 PM|GerdR|LINK
Windows Server 2012 R2 with IIS 8.5
ON_PARSE_COMMAND(myfunction, CxxxExtension, IT_PSTR)
void CsxxxExtension::myfunction( CHttpServerContext* pCtxt, char* params)
Result: Works fine, but intermittent heap error in case of parallel requests, occuring each 3-7 days in a productive environment.
After days of analysis: it seems that the url-decoding of %xx in ISAPI-MFC (file isapi.cpp) assumes ending 0 in the parameter string, which intermittently (after several hundred parallel requests, three active threads) is not the case. MFC routine then overwrites
heap control blocks and we obtain a break with _ASSERTE( _CrtCheckMemory());.
This is why we switched to IT_RAW:
ON_PARSE_COMMAND(myfunction, CxxxExtension, IT_RAW)
void CxxxExtension::myfunction( CHttpServerContext* pCtxt, void* pVoid, DWORD dwBytes)
Problem: dwBytes does not point behind the string value given in pVoid, but around 20 Byes more, covering the next block in heap. It looks like the length of "MfcISAPICommand=myfunction" in the URL query string is not subtracted from dwBytes.
Moreover, no reliable ending 0 at end of string pVoid. So it is necessary to "guess" the real end of pVoid data.
We now live with Version 2. Quite unsatisfying situation. How can it be that such bugs are hidden in a relatively old and proven technology like ISAPI? Any hints what we could have done wrong?
Our ISAPI extensiondll is compiled with /MT and uses the standard Windows MFC libraries.
PS on October 11, 2018
I'm not sure whether the version of "isapi.cpp" which I found in internet is still the one Microsoft uses to build the MFCfiles. But in this version the error is quite clear:
// coding from isapi.cpp:
if (*pb == IT_RAW)
pStack = StoreRawStackParameter(pStack, IT_PSTR, pbParam);
pStack = StoreRawStackParameter(pStack, IT_I4,
which means that the total length of the query string is passed to "myfunction",but pbParam already proints behind the first part of the query string which is "MfcISAPICommand=myfunction".
1 hour, 34 minutes ago|DevPreSupport_MSFT|LINK
ISAPI project template has been removed in visual studio 2005. There is an article explain this:
This is by design. If you find bugs. Product team may be not have plan to fix it. It is also hard for us to reproduce and troubleshot this type issue. Currently, ISAPI extensions were analogous to HttpHandlers. If you are looking to extend web server functionality,
I would suggest you use handler instead.