https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a4b6e0d929b0696fa7c9a258476ea1ff5778a125

commit a4b6e0d929b0696fa7c9a258476ea1ff5778a125
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Nov 16 22:47:05 2019 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Nov 17 23:21:47 2019 +0100

    [SDK:RTL] Add one validity check + comment documentation for 
RtlDispatchException().
    
    - RtlDispatchException(): Check for invalid stack in 
ExceptionContinueSearch handler
      and bail out if so.
    - Update few comments and fix a typo.
    - Add a documenting comment about SafeSEH functionality support.
      See e.g. the following articles:
      
https://www.optiv.com/blog/old-meets-new-microsoft-windows-safeseh-incompatibility
      
https://msrc-blog.microsoft.com/2012/01/10/more-information-on-the-impact-of-ms12-001/
---
 sdk/lib/rtl/i386/except.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/sdk/lib/rtl/i386/except.c b/sdk/lib/rtl/i386/except.c
index 7054a0f02e0..530d5c75253 100644
--- a/sdk/lib/rtl/i386/except.c
+++ b/sdk/lib/rtl/i386/except.c
@@ -113,11 +113,18 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
                 continue;
             }
 
-            /* Set invalid stack and return false */
+            /* Set invalid stack and bail out */
             ExceptionRecord->ExceptionFlags |= EXCEPTION_STACK_INVALID;
             return FALSE;
         }
 
+        //
+        // TODO: Implement and call here 
RtlIsValidHandler(RegistrationFrame->Handler)
+        // for supporting SafeSEH functionality, see the following articles:
+        // 
https://www.optiv.com/blog/old-meets-new-microsoft-windows-safeseh-incompatibility
+        // 
https://msrc-blog.microsoft.com/2012/01/10/more-information-on-the-impact-of-ms12-001/
+        //
+
         /* Check if logging is enabled */
         RtlpCheckLogException(ExceptionRecord,
                               Context,
@@ -144,7 +151,7 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
         {
             /* Continue execution */
             case ExceptionContinueExecution:
-
+            {
                 /* Check if it was non-continuable */
                 if (ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE)
                 {
@@ -161,20 +168,25 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
                 else
                 {
                     /* In user mode, call any registered vectored continue 
handlers */
-                    RtlCallVectoredContinueHandlers(ExceptionRecord,
-                                                    Context);
+                    RtlCallVectoredContinueHandlers(ExceptionRecord, Context);
 
                     /* Execution continues */
                     return TRUE;
                 }
+            }
 
             /* Continue searching */
             case ExceptionContinueSearch:
+                if (ExceptionRecord->ExceptionFlags & EXCEPTION_STACK_INVALID)
+                {
+                    /* We have an invalid stack, bail out */
+                    return FALSE;
+                }
                 break;
 
             /* Nested exception */
             case ExceptionNestedException:
-
+            {
                 /* Turn the nested flag on */
                 ExceptionRecord->ExceptionFlags |= EXCEPTION_NESTED_CALL;
 
@@ -185,10 +197,11 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
                     NestedFrame = DispatcherContext.RegistrationPointer;
                 }
                 break;
+            }
 
             /* Anything else */
             default:
-
+            {
                 /* Set up the exception record */
                 ExceptionRecord2.ExceptionRecord = ExceptionRecord;
                 ExceptionRecord2.ExceptionCode = STATUS_INVALID_DISPOSITION;
@@ -198,13 +211,14 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
                 /* Raise the exception */
                 RtlRaiseException(&ExceptionRecord2);
                 break;
+            }
         }
 
         /* Go to the next frame */
         RegistrationFrame = RegistrationFrame->Next;
     }
 
-    /* Unhandled, return false */
+    /* Unhandled, bail out */
     return FALSE;
 }
 
@@ -335,22 +349,24 @@ RtlUnwind(IN PVOID TargetFrame OPTIONAL,
                                                       Context,
                                                       &DispatcherContext,
                                                       
RegistrationFrame->Handler);
+
             switch(Disposition)
             {
                 /* Continue searching */
                 case ExceptionContinueSearch:
                     break;
 
-                /* Collission */
-                case ExceptionCollidedUnwind :
-
+                /* Collision */
+                case ExceptionCollidedUnwind:
+                {
                     /* Get the original frame */
                     RegistrationFrame = DispatcherContext.RegistrationPointer;
                     break;
+                }
 
                 /* Anything else */
                 default:
-
+                {
                     /* Set up the exception record */
                     ExceptionRecord2.ExceptionRecord = ExceptionRecord;
                     ExceptionRecord2.ExceptionCode = 
STATUS_INVALID_DISPOSITION;
@@ -360,6 +376,7 @@ RtlUnwind(IN PVOID TargetFrame OPTIONAL,
                     /* Raise the exception */
                     RtlRaiseException(&ExceptionRecord2);
                     break;
+                }
             }
 
             /* Go to the next frame */

Reply via email to