1) Without symbols
a) The faulting Stack
The stack backtrace of the thread that caused the Stack Overflow would look like:
0:006> kvn50
# ChildEBP RetAddr Args to Child
00 01333004 02711658 001ade10 00000078 01333024 badext!HttpExtensionProc+0xefed
01 01333014 02711658 001ade10 00000078 01333034 badext!HttpExtensionProc+0xefed
02 01333024 02711658 001ade10 00000078 01333044 badext!HttpExtensionProc+0xefed
03 01333034 02711658 001ade10 00000078 01333054 badext!HttpExtensionProc+0xefed
04 01333044 02711658 001ade10 00000078 01333064 badext!HttpExtensionProc+0xefed
05 01333054 02711658 001ade10 00000078 01333074 badext!HttpExtensionProc+0xefed
06 01333064 02711658 001ade10 00000078 01333084 badext!HttpExtensionProc+0xefed
07 01333074 02711658 001ade10 00000078 01333094 badext!HttpExtensionProc+0xefed
08 01333084 02711658 001ade10 00000078 013330a4 badext!HttpExtensionProc+0xefed
09 01333094 02711658 001ade10 00000078 013330b4 badext!HttpExtensionProc+0xefed
0a 013330a4 02711658 001ade10 00000078 013330c4 badext!HttpExtensionProc+0xefed
0b 013330b4 02711658 001ade10 00000078 013330d4 badext!HttpExtensionProc+0xefed
0c 013330c4 02711658 001ade10 00000078 013330e4 badext!HttpExtensionProc+0xefed
0d 013330d4 02711658 001ade10 00000078 013330f4 badext!HttpExtensionProc+0xefed
0e 013330e4 02711658 001ade10 00000078 01333104 badext!HttpExtensionProc+0xefed
0f 013330f4 02711658 001ade10 00000078 01333114 badext!HttpExtensionProc+0xefed
10 01333104 02711658 001ade10 00000078 01333124 badext!HttpExtensionProc+0xefed
11 01333114 02711658 001ade10 00000078 01333134 badext!HttpExtensionProc+0xefed
12 01333124 02711658 001ade10 00000078 01333144 badext!HttpExtensionProc+0xefed
13 01333134 02711658 001ade10 00000078 01333154 badext!HttpExtensionProc+0xefed
It's obvious that in this stack backtrace, a function in badext.dll (we don't know the function name yet because we don't have
have the symbols lined up yet) is calling itself without a satisfied stopping condition. This recursive call ended up by a stack
overflow which is basically an exception.
Note that there are other causes of a stack overflow other than recursive calls or infinite loops. Please refer to the windbg help. Search for "Stack Overflow"
0:001> .lastevent
Last event: 738.824: Stack overflow - code c00000fd (first chance)
b) The regiters values
0:006> r
eax=001ade10 ebx=00000003 ecx=0136f760 edx=00075000 esi=00070000 edi=001ade10
eip=02711650 esp=01333000 ebp=01333004 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00010202
badext!HttpExtensionProc+0xefed:
02711650 ff7508 push dword ptr [ebp+0x8] ss:0023:0133300c=001ade10
c) The disassmbly code
0:006> u eip
badext!HttpExtensionProc+0xefed:
02711650 ff7508 push dword ptr [ebp+0x8]
02711653 e8f2ffffff call badext!FindChar (0271164a)
02711658 5d pop ebp
02711659 c20800 ret 0x8 badext!HttpExtensionProc+0xefed
0271165c 55 push ebp
0271165d 8bec mov ebp,esp
0271165f 81ec0c040000 sub esp,0x40c
02711665 53 push ebx
2) With symbols including public symbols of "badExt.dll"
First, we need to add the symbol path(company wide symbols) as well as public symbols of our dll a) Using the GUI:
- Click "File"
- Click "Symbol File Path"
- Type in SRV*C:\LabSymbols*\\symbols\symbols;C:\IISDebugLabs\symbols\Pub a
nd hit Enter
b) Using the ".sympath+" command:
.sympath+ SRV*C:\LabSymbols*\\symbols\symbols;C :\IISDebugLabs\symbols\Pub
Note: For more information on setting the symbol path for windbg, please refer to the debugger documentation for the .sympath command. This will describe
the "downstream store" feature that lets you download symbols to a symbol server of your own.
The stack backtrace of the thread that caused teh Stack Overflow would look like:
0:006> kvn50
# ChildEBP RetAddr Args to Child
00 01333004 02711658 001ade10 00000078 01333024 badext!FindChar+0x6
01 01333014 02711658 001ade10 00000078 01333034 badext!FindChar+0xe
02 01333024 02711658 001ade10 00000078 01333044 badext!FindChar+0xe
03 01333034 02711658 001ade10 00000078 01333054 badext!FindChar+0xe
04 01333044 02711658 001ade10 00000078 01333064 badext!FindChar+0xe
05 01333054 02711658 001ade10 00000078 01333074 badext!FindChar+0xe
06 01333064 02711658 001ade10 00000078 01333084 badext!FindChar+0xe
07 01333074 02711658 001ade10 00000078 01333094 badext!FindChar+0xe
08 01333084 02711658 001ade10 00000078 013330a4 badext!FindChar+0xe
09 01333094 02711658 001ade10 00000078 013330b4 badext!FindChar+0xe
0a 013330a4 02711658 001ade10 00000078 013330c4 badext!FindChar+0xe
0b 013330b4 02711658 001ade10 00000078 013330d4 badext!FindChar+0xe
0c 013330c4 02711658 001ade10 00000078 013330e4 badext!FindChar+0xe
0d 013330d4 02711658 001ade10 00000078 013330f4 badext!FindChar+0xe
0e 013330e4 02711658 001ade10 00000078 01333104 badext!FindChar+0xe
0f 013330f4 02711658 001ade10 00000078 01333114 badext!FindChar+0xe
10 01333104 02711658 001ade10 00000078 01333124 badext!FindChar+0xe
.......
.......
.......
So basically here, we can confirm that the call to the function "FindChar()" is recursive without a satisfied stopping condition. This enough to tell the customer
that the problem is coming from the function "FindChar()" in the custom ISAPI extension "badext.dll"
Advanced Technique
In IIS4 and 5, each thread has a stack of a maximum size of 256k. Please refer to teh following KB:
PRB: Stack Size Now 256 K in Internet Information Server 4.0 WGID:246
ID: 189888.KB.EN-US CREATED: 1998-07-21 MODIFIED: 2001-07-16
We will be using the !teb command (Thread Environment Variable) to check the stack size.
0:006> !teb
TEB at 7FFDB000
ExceptionList: 136f760
Stack Base: 1370000
Stack Limit: 1331000
SubSystemTib: 0
FiberData: 1e00
ArbitraryUser: 0
Self: 7ffdb000
EnvironmentPtr: 0
ClientId: 640.83c
Real ClientId: 640.83c
RpcHandle: 0
Tls Storage: 0
PEB Address: 7ffdf000
LastErrorValue: 0
LastStatusValue: c0000023
Count Owned Locks:0
HardErrorsMode: 0
Finding the current size:
0:006> ?(1370000-1331000)
Evaluate expression: 258048 = 0003f000
0:006> ?(258048 /1024)
Evaluate expression: 594 = 00000252
This shows that the current size now is 252 KB which is almost the limit
To verify that the symbols are lined up properly for our extension, issue this command.
0:006> lmv mbadext
start end module name 06470000 06475000
badext (pdb symbols) C :\IISDebugLabs\symbols\Pub
Loaded symbol image file: C:\IISDebuglabs\www\App\badext.dll Image path: C:\IISDebuglabs\www\App\badext.dll
Timestamp: Wed Jan 29 18:07:14 2003 (3E385EA2)
Checksum: 0000EBCD
File version: 5.0.0.0
Product version: 5.0.0.0
File flags: 0 (Mask 3F)
File OS: 40004 NT Win32
File type: 2.0 Dll
File date: 00000000.00000000
CompanyName: Microsoft Corporation
ProductName: Internet Information Services
InternalName: badEXT.dll
OriginalFilename: badEXT.dll
ProductVersion: 5.00.0984
FileVersion: 5.00.0984
FileDescription: badEXT Test
LegalCopyright: Copyright (C) Microsoft Corp. 1981-1999
3) with Private Symbols "badExt.dll"
First, we need to add the symbol path(company wide symbols) as well as private symbols of our dll a) Using the GUI:
- Click "File"
- Click "Symbol File Path"
- Type in SRV*C:\LabSymbols*\\symbols\symbols;C:\IISDebugLabs\symbols\Pri a
nd hit Enter
b) Using the ".sympath+" command:
.sympath+ SRV*C:\LabSymbols*\\symbols\symbols;C :\IISDebugLabs\symbols\Pri
The stack backtrace of the thread that caused the Stack Overflow would look like:
0:001> kvn50
# ChildEBP RetAddr Args to Child
00 00b63004 0ac81658 028a3378 00000078 00b63024 badext!FindChar+0x6 (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 347]
01 00b63014 0ac81658 028a3378 00000078 00b63034 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
02 00b63024 0ac81658 028a3378 00000078 00b63044 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
03 00b63034 0ac81658 028a3378 00000078 00b63054 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
04 00b63044 0ac81658 028a3378 00000078 00b63064 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
05 00b63054 0ac81658 028a3378 00000078 00b63074 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
06 00b63064 0ac81658 028a3378 00000078 00b63084 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
07 00b63074 0ac81658 028a3378 00000078 00b63094 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
08 00b63084 0ac81658 028a3378 00000078 00b630a4 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
09 00b63094 0ac81658 028a3378 00000078 00b630b4 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
0a 00b630a4 0ac81658 028a3378 00000078 00b630c4 badext!FindChar+0xe (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\extDBG\badext.cpp @ 352]
......
......
......
Looking at the source code:
char* FindChar(char* sz, char c)
{
char* ch = NULL;
{
ch = sz++;
sz = FindChar( ch, c ); //Line 347
}
return sz;
}
As you see this recursive function will never stop execution becuase there is no stopping condition. In real life
this kind of problems would happen if the stopping condition is never met for some reason.