Debug Labs


Divide-By-Zero Exception in Component Code  

This lab will demonstrate an Integer Divide-By-Zero exception in a dll. In this scenario, a DBZ Exception in the ISAPI filter "badFil.dll".

This scenario is presented in 2 variations, the 1st variation shows the exception in the main thread running the HTTPFilterProc, while the second variation shows the exception in a spawned thread other than the main thread.

1- Lab Setup
	

Note: This lab assumes that you have already installed the necessary lab files to run it.

1-Install the ISAPI Filter

 

- Right Click the Server Name

- Click "Properties"

- In the "WWW Service" Master Properties, click "Edit"

- In the "ISAPI Filters" tab, click "Add"

- In the "Filter Name" type in "BadFilter"

- In the "Executable", browse to C:\IISDebugLabs\www\App\badfil.dll

- Click "Apply" and click "Ok" all teh way out.

 

2- Restart the IIS Admin service

- Right Click the Server Name

- Click "Restart IIS" and Click "Ok"

 

3- Attach the debugger to inetinfo.exe

a) Using the GUI:

- Click "File"

- Click "Attach to Process"

- Select "inetinfo.exe" and click "OK"

b) Using the command prompt

-Type in "windng -pn inetinfo.exe" without quotation marks and hit "Enter"

 

4- In windbg command line, type in "g" with no quotation marks and press Enter

 

 

2- Run Scenario

1- Click the "Cause DBZ Exception V:1" button the first time to cause a 1st chance Integer Divide-By-Zero Exception in inetinfo.exe.
 Note that the debugger breaks and diplays 
	a- Comments about the exception
b- The value of the registers
c- The module where the AV happened
d- The assembly line that caused the AV
2- To study the second variation of this lab, click the "Cause DBZ Exception V:2" button.

                                                                                     

1) Integer Divide-By-Zero Exception in the main thread running HttpFilterProc:  (Variation 1)

1- Debug Annotation

 

1) Without symbols

 

a) The faulting Stack

 

The stack backtrace of the thread that caused the Divide-ByZero Exception would look like:

 

 

0:008> kvn50

# ChildEBP RetAddr Args to Child

WARNING: Stack unwind information not available. Following frames may be wrong.

00 0129f5dc 016b17a6 00000001 00e84f20 00e84e00 badfil!HttpFilterProc+0x862

01 0129fbf4 65f0354f 00000001 00004000 08000002 badfil!HttpFilterProc+0x2a4

02 0129fc1c 65f034bc 000003e9 00004000 00000002 w3svc!STR::Copy+0x11a

03 0129fc50 65f02cad 0129fedc 0129fedc 00e84648 w3svc!STR::Copy+0x87

04 0129fca8 65f02ac1 006aa818 0000019b 0129fcd4 w3svc!CLIENT_CONN::OnSessionStartup+0xa69

05 0129fcec 65f029b5 006aa818 0000019b 0129fedc w3svc!CLIENT_CONN::OnSessionStartup+0x87d

06 0129fd2c 65f028f8 0129fea4 0129fedc 0129feb8 w3svc!CLIENT_CONN::OnSessionStartup+0x771

07 0129fd4c 65f027b3 0129fea4 0129fedc 0129feb8 w3svc!CLIENT_CONN::OnSessionStartup+0x6b4

08 0129fec4 65f020d7 0129fedc 011a3568 0129ff20 w3svc!CLIENT_CONN::OnSessionStartup+0x56f

09 0129fee4 65f01b47 00000000 00000000 00000000 w3svc!HTTP_HEADERS::Reset+0x311

0a 0129ff08 65f01aa5 0129ff20 77e873b2 011a3568 w3svc+0x1b47

0b 0129ff4c 6d701443 011a3568 0000019b 00104f08 w3svc+0x1aa5

0c 0129ff80 6d702203 00000000 0000019b 011a356c ISATQ!AtqReadSocket+0x228

0d 77deec86 ece868ff fb6877dc 6477db19 000000a1 ISATQ!AtqWriteSocket+0x495

0e 6aec8b55 00000000 00000000 00000000 00000000 0xece868ff

 

In this stack backtrace, it is clear that the culprit is "badFil.dll". So it is enough to tell the customer to contact the dll vendor to fix it. If it is an in-house component and the customer would like help

from Microsoft, they should open an advisory case to troubleshoot the issue further.

 

b) The regiters values

 

0:008> r

eax=00000001 ebx=00000003 ecx=00000000 edx=00000000 esi=78002041 edi=00e87358

eip=016b1d64 esp=0129f5dc ebp=0129f5dc iopl=0 nv up ei pl zr na po nc

cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246

badfil!HttpFilterProc+862:

016b1d64 f7f9 idiv ecx

 

c) The disassmbly code

 

0:008> u eip

badfil!HttpFilterProc+862:

016b1d64 f7f9 idiv ecx

016b1d66 eb1e jmp badfil!HttpFilterProc+0x884 (016b1d86)

016b1d68 837d0802 cmp dword ptr [ebp+0x8],0x2

016b1d6c 7515 jnz badfil!HttpFilterProc+0x881 (016b1d83)

016b1d6e 8d4508 lea eax,[ebp+0x8]

016b1d71 50 push eax

016b1d72 33c0 xor eax,eax

016b1d74 50 push eax

 

 

2) With symbols including public symbols of "badFil.dll"

 

First, we need to add the public symbol path(company wide symbols) as well as symbols of our dll

a) Using the GUI:

- Click "File"

- Click "Symbol File Path"

- Type in SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols;C:\IISDebugLabs\symbols\Pub and hit Enter

b) Using the ".sympath+" command:

0:008> .sympath+ SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols

Symbol search path is: SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols

 

0:008> .sympath+ C :\IISDebugLabs\symbols\Pub (where public symbols of badFil.dll are located)

Symbol search path is:SRV*C:\LabSymbols*http://msdl.microsoft.com/download/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 the DBZ exception would look like:

 

0:008> kvn50

# ChildEBP RetAddr Args to Child

00 0129f5dc 016b17a6 00000001 00e84f20 00e84e00 badfil!doDZ1+0xf

01 0129fbf4 65f0354f 00000001 00004000 08000002 badfil!HttpFilterProc+0x2a4

02 0129fc1c 65f034bc 000003e9 00004000 00000002 w3svc!FILTER_LIST::NotifyFilters+0x9d (FPO: [Non-Fpo])

03 0129fc50 65f02cad 0129fedc 0129fedc 00e84648 w3svc!HTTP_FILTER::NotifyPreProcHeaderFilters+0x3e (FPO: [Non-Fpo])

04 0129fca8 65f02ac1 006aa818 0000019b 0129fcd4 w3svc!HTTP_REQUEST::Parse+0x372 (FPO: [Non-Fpo])

05 0129fcec 65f029b5 006aa818 0000019b 0129fedc w3svc!HTTP_REQ_BASE::OnCompleteRequest+0x28 (FPO: [Non-Fpo])

06 0129fd2c 65f028f8 0129fea4 0129fedc 0129feb8 w3svc!HTTP_REQ_BASE::UnWrapRequest+0x1e6 (FPO: [Non-Fpo])

07 0129fd4c 65f027b3 0129fea4 0129fedc 0129feb8 w3svc!HTTP_REQ_BASE::OnFillClientReq+0x6c (FPO: [Non-Fpo])

08 0129fec4 65f020d7 0129fedc 011a3568 0129ff20 w3svc!HTTP_REQUEST::DoWork+0x8b (FPO: [Non-Fpo])

09 0129fee4 65f01b47 00000000 00000000 00000000 w3svc!CLIENT_CONN::DoWork+0x1aa (FPO: [Non-Fpo])

0a 0129ff08 65f01aa5 0129ff20 77e873b2 011a3568 w3svc!CreateClient+0x7b (FPO: [Non-Fpo])

0b 0129ff4c 6d701443 011a3568 0000019b 00104f08 w3svc!W3OnConnectEx+0x118 (FPO: [Non-Fpo])

0c 0129ff80 6d702203 00000000 0000019b 011a356c ISATQ!AtqpProcessContext+0x23a (FPO: [Non-Fpo])

0d 0129ffb4 77e887dd abcdef01 00000000 00012047 ISATQ!AtqPoolThread+0x1a8 (FPO: [EBP 0x0129ffec] [1,4,4])

0e 0129ffec 00000000 6d7091f7 abcdef01 00000000 KERNEL32!BaseThreadStart+0x52 (FPO: [Non-Fpo])

 

 

Now, with the public symbols lined up, we see that the last call that caused the Divide-By-Zero Exception was to the function "doDZ1" that was called from the ISAPI filter

entry point "HttpFilterProc".

 

Again, In this call stack, it is clear that the culprit is "badFil.dll". So it is enough to tell the customer to contact the dll vendor to fix it. If it is an in-house component and the customer would like help

from Microsoft, they should open an advisory case to troubleshoot the issue further.

 

 

3) with Private Symbols "badFil.dll"

 

Point the debugger to use the private symbols

For company wide internal symbols, use \\symbols\symbols

For the component private symbols, use C:\IISDebugLabs\Symbols\Pri

 

The stack backtrace of the thread that caused the DBZ would look like:

 

0:008> kvn50

# ChildEBP RetAddr Args to Child

00 0129f5dc 016b17a6 00000001 00e84f20 00e84e00 badfil!doDZ1+0xf (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\filDBG\badfil.cpp @ 748]

01 0129fbf4 65f0354f 00000001 00004000 08000002 badfil!HttpFilterProc+0x2a4 (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\filDBG\badfil.cpp @ 293]

02 0129fc1c 65f034bc 000003e9 00004000 00000002 w3svc!FILTER_LIST::NotifyFilters+0x9d (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpfilt.cxx @ 968]

03 0129fc50 65f02cad 0129fedc 0129fedc 00e84648 w3svc!HTTP_FILTER::NotifyPreProcHeaderFilters+0x4c (FPO: [Non-Fpo]) (CONV: thiscall) [.\filter.hxx @ 473]

04 0129fca8 65f02ac1 006aa818 0000019b 0129fcd4 w3svc!HTTP_REQUEST::Parse+0x380 (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpreq.cxx @ 1497]

05 0129fcec 65f029b5 006aa818 0000019b 0129fedc w3svc!HTTP_REQ_BASE::OnCompleteRequest+0x36 (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 1289]

06 0129fd2c 65f028f8 0129fea4 0129fedc 0129feb8 w3svc!HTTP_REQ_BASE::UnWrapRequest+0x1f4 (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 634]

07 0129fd4c 65f027b3 0129fea4 0129fedc 0129feb8 w3svc!HTTP_REQ_BASE::OnFillClientReq+0x7a (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 253]

08 0129fec4 65f020d7 0129fedc 011a3568 0129ff20 w3svc!HTTP_REQUEST::DoWork+0x99 (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\httpreq.cxx @ 639]

09 0129fee4 65f01b47 00000000 00000000 00000000 w3svc!CLIENT_CONN::DoWork+0x1aa (FPO: [Non-Fpo]) (CONV: thiscall) [D:\nt\private\inet\iis\svcs\w3\server\conn.cxx @ 781]

0a 0129ff08 65f01aa5 0129ff20 77e873b2 011a3568 w3svc!CreateClient+0x7b (FPO: [Non-Fpo]) (CONV: stdcall) [D:\nt\private\inet\iis\svcs\w3\server\connect.cxx @ 310]

0b 0129ff4c 6d701443 011a3568 0000019b 00104f08 w3svc!W3OnConnectEx+0x118 (FPO: [Non-Fpo]) (CONV: stdcall) [D:\nt\private\inet\iis\svcs\w3\server\connect.cxx @ 215]

0c 0129ff80 6d702203 00000000 0000019b 011a356c ISATQ!AtqpProcessContext+0x23a (FPO: [Non-Fpo]) (CONV: stdcall) [D:\nt\private\inet\iis\svcs\infocomm\atq\atqsupp.cxx @ 883]

0d 0129ffb4 77e887dd abcdef01 00000000 00012047 ISATQ!AtqPoolThread+0x1a8 (FPO: [EBP 0x0129ffec] [1,4,4]) (CONV: stdcall) [D:\nt\private\inet\iis\svcs\infocomm\atq\atqsupp.cxx @ 1127]

0e 0129ffec 00000000 6d7091f7 abcdef01 00000000 KERNEL32!BaseThreadStart+0x52 (FPO: [Non-Fpo]) (CONV: stdcall) [D:\nt\private\windows\base\client\support.c @ 460]

 

 

As mentioned above, badFil.dll encountered a DBZ exception. The function that encountered the exception is "doDZ1" that was called from

the filter's entry point "HttpFilterProc". It is helpful to exact information like what request caused the DBZ

In this special case, using the debugger "kp" command will show the exact request.

 

0:008> kpn50

# ChildEBP RetAddr

00 0129f5dc 016b17a6 badfil!doDZ1(int Variation = 1)+0xf [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\filDBG\badfil.cpp @ 748]

01 0129fbf4 65f0354f badfil!HttpFilterProc(struct _HTTP_FILTER_CONTEXT * pfc = 0x00000001, unsigned long NotificationType = 0x4000, void * pvData = 0x08000002)+0x2a4 [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\filDBG\badfil.cpp @ 293]

02 0129fc1c 65f034bc w3svc!FILTER_LIST::NotifyFilters(class HTTP_FILTER * pFilter = 0x000003e9, unsigned long NotificationType = 0x4000, struct _HTTP_FILTER_CONTEXT * phfc = 0x00000002, void * NotificationData = 0x0129fc3c, int * pfFinished = 0x0129fedc, int fNotifyAll = 0)+0x9d [D:\nt\private\inet\iis\svcs\w3\server\httpfilt.cxx @ 968]

03 0129fc50 65f02cad w3svc!HTTP_FILTER::NotifyPreProcHeaderFilters(int * pfFinished = 0x0129fedc)+0x4c [.\filter.hxx @ 473]

04 0129fca8 65f02ac1 w3svc!HTTP_REQUEST::Parse(char * pchRequest = 0x006aa818 "GET /iisdebuglabs/site/fil_dz1.htm?sf=dz1_v1 HTTP/1.1???", unsigned long cbData = 0x19b, unsigned long * pcbExtraData = 0x0129fcd4, int * pfHandled = 0x0129fce8, int * pfFinished = 0x0129fedc)+0x380 [D:\nt\private\inet\iis\svcs\w3\server\httpreq.cxx @ 1497]

05 0129fcec 65f029b5 w3svc!HTTP_REQ_BASE::OnCompleteRequest(char * pchRequest = 0x006aa818 "GET /iisdebuglabs/site/fil_dz1.htm?sf=dz1_v1 HTTP/1.1???", unsigned long cbData = 0x19b, int * pfFinished = 0x0129fedc, int * pfContinueProcessingRequest = 0x0129feb8)+0x36 [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 1289]

06 0129fd2c 65f028f8 w3svc!HTTP_REQ_BASE::UnWrapRequest(int * pfCompleteRequest = 0x0129fea4, int * pfFinished = 0x0129fedc, int * pfContinueProcessingRequest = 0x0129feb8)+0x1f4 [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 634]

07 0129fd4c 65f027b3 w3svc!HTTP_REQ_BASE::OnFillClientReq(int * pfCompleteRequest = 0x0129fea4, int * pfFinished = 0x0129fedc, int * pfContinueProcessingRequest = 0x0129feb8)+0x7a [D:\nt\private\inet\iis\svcs\w3\server\httpio.cxx @ 253]

08 0129fec4 65f020d7 w3svc!HTTP_REQUEST::DoWork(int * pfFinished = 0x0129fedc)+0x99 [D:\nt\private\inet\iis\svcs\w3\server\httpreq.cxx @ 639] 09 0129fee4 65f01b47 w3svc!CLIENT_CONN::DoWork(unsigned long BytesWritten = 0, unsigned long CompletionStatus = 0, int fIOCompletion = 0)+0x1aa [D:\nt\private\inet\iis\svcs\w3\server\conn.cxx @ 781]

0a 0129ff08 65f01aa5 w3svc!CreateClient(struct _CLIENT_CONN_PARAMS * ClientParam = 0x0129ff20)+0x7b [D:\nt\private\inet\iis\svcs\w3\server\connect.cxx @ 310]

0b 0129ff4c 6d701443 w3svc!W3OnConnectEx(void * patqContext = 0x011a3568, unsigned long cbWritten = 0x19b, unsigned long err = 0x104f08, struct _OVERLAPPED * lpo = 0x00e83c20)+0x118 [D:\nt\private\inet\iis\svcs\w3\server\connect.cxx @ 215]

0c 0129ff80 6d702203 ISATQ!AtqpProcessContext(struct ATQ_CONTEXT * pAtqContext = 0x00000000, unsigned long cbWritten = 0x19b, struct _OVERLAPPED * lpo = 0x011a356c, int fRet = 1)+0x23a [D:\nt\private\inet\iis\svcs\infocomm\atq\atqsupp.cxx @ 883]

0d 0129ffb4 77e887dd ISATQ!AtqPoolThread(unsigned long * param = 0xece868ff)+0x1a8 [D:\nt\private\inet\iis\svcs\infocomm\atq\atqsupp.cxx @ 1127]

0e 0129ffec 00000000 KERNEL32!BaseThreadStart( * lpStartAddress = 0x6d7091f7, void * lpParameter = 0xabcdef01)+0x52 [D:\nt\private\windows\base\client\support.c @ 460]

 

Notice in frame 00 and 01 the line of the code as well as the name and location of the source code. Going back to the source code in badFil.cpp:

 

Line 146 looks like

 

 

DWORD WINAPI HttpFilterProc( HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData )

{

DWORD dwRet;

//

// If we don't have a context already, create one now

//

.....

.....

else if (!strncmp(szS, "dz1", 3))

{

return doDZ1(Variation); //Line 293

}

....

....

return dwRet;

}

 

Line 748 looks like

 

DWORD doDZ1(int Variation)

{

DWORD dwThreadID;

HANDLE hThread;

 

if (1 == Variation )

{

int i = 0;

int j = 1;

j = j / i; //line 748

return j;

}

if (2 == Variation)

{

hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DBZ, NULL, 0, &dwThreadID);

}

return 1;

}

 

 

2) Integer Divide-By-Zero Exception in a spawned thread: (Variation 2)

1- Debug Annotation

 

1) Without symbols

 

a) The faulting Stack

 

The stack backtrace of the thread that caused the Divide-ByZero Exception would look like:

 

0:017> kv

ChildEBP RetAddr Args to Child

WARNING: Stack unwind information not available. Following frames may be wrong.

018cffec 00000000 016b1e20 00000000 00000000 badfil!HttpFilterProc+0x924

 

 

In this stack backtrace, it is clear that the culprit is "badFil.dll". So it is enough to tell the customer to contact the dll vendor to fix it. If it is an in-house component and the customer would like help

from Microsoft, they should open an advisory case to troubleshoot the issue further.

 

b) The regiters values

 

 

0:017> r

eax=00000001 ebx=00000000 ecx=00000000 edx=00000000 esi=ffffffff edi=77e86ec8

eip=016b1e26 esp=018cffb8 ebp=018cffec iopl=0 nv up ei pl zr na po nc

cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000246

badfil!HttpFilterProc+924:

016b1e26 f7f9 idiv ecx

 

c) The disassmbly code

 

 

0:017> u eip

badfil!HttpFilterProc+924:

016b1e26 f7f9 idiv ecx

016b1e28 c3 ret

016b1e29 55 push ebp

016b1e2a 8bec mov ebp,esp

016b1e2c 83ec0c sub esp,0xc

016b1e2f a040306b01 mov al,[badfil!HttpFilterProc+0x1b3e (016b3040)]

016b1e34 53 push ebx

016b1e35 33db xor ebx,ebx

 

 

2) With symbols including public symbols of "badFil.dll"

 

First, we need to add the public symbol path(company wide symbols) as well as symbols of our dll

a) Using the GUI:

- Click "File"

- Click "Symbol File Path"

- Type in SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols;C:\IISDebugLabs\symbols\Pub and hit Enter

b) Using the ".sympath+" command:

0:008> .sympath+ SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols

Symbol search path is: SRV*C:\LabSymbols*http://msdl.microsoft.com/download/symbols

 

0:008> .sympath+ C :\IISDebugLabs\symbols\Pub (where public symbols of badFil.dll are located)

Symbol search path is:SRV*C:\LabSymbols*http://msdl.microsoft.com/download/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 the DBZ exception would look like:

 

0:017> kvn50

# ChildEBP RetAddr Args to Child

00 018cffec 00000000 016b1e20 00000000 00000000 badfil!DBZ+0x6

 

  

Now, with the public symbols lined up, we see that the last call that caused the Divide-By-Zero Exception was to the function "DBZ()".

 

Again, In this call stack, it is clear that the culprit is "badFil.dll". So it is enough to tell the customer to contact the dll vendor to fix it. If it is an in-house component and the customer would like help

from Microsoft, they should open an advisory case to troubleshoot the issue further.

 

 

3) with Private Symbols "badFil.dll"

The stack backtrace of the thread that caused the DBZ would look like:

 

0:017> kvn50

# ChildEBP RetAddr Args to Child

00 018cffec 00000000 016b1e20 00000000 00000000 badfil!DBZ+0x6 (CONV: stdcall) [H:\nT\PRIVATE\inet\iis\svcs\w3\gateways\filDBG\badfil.cpp @ 830]

 

 

Notice in frame 00 the line of the code as well as the name and location of the source code. Going back to the source code in badfil.cpp:

 

Line 830 looks like

 

 

DWORD DBZ()

{

int i = 0;

int j = 1;

j = j / i; //line 830

return j;

}


- Microsoft Confidential -