[cpp-sp] branch main updated: SSPCPP-904 Catch exceptions from the IIS87 filter

Rod Widdowson rdw at steadingsoftware.com
Thu Aug 27 14:42:59 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository cpp-sp.

View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=a2cfc1526b86d36d2afd921a1bf1029e79af4267

The following commit(s) were added to refs/heads/main by this push:
       new  a2cfc152  SSPCPP-904 Catch exceptions from the IIS87 filter
a2cfc152 is described below

commit a2cfc1526b86d36d2afd921a1bf1029e79af4267
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Aug 27 15:40:45 2020 +0100

    SSPCPP-904 Catch exceptions from the IIS87 filter
    
    https://issues.shibboleth.net/jira/browse/SSPCPP-904
    
    Minimal fix to catch the exceptions we know we need to catch
    (taken from ISAPI) and also handle catchAll.
    
    Additionally our "communicate via exceptions" kludge has had some
    logging added.
    
    Further fixes to follow after 3.1.0.2 ships
---
 iis7_shib/IIS7Request.cpp    |  1 +
 iis7_shib/ShibHttpModule.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/iis7_shib/IIS7Request.cpp b/iis7_shib/IIS7Request.cpp
index cf2f1578..658fb3d0 100644
--- a/iis7_shib/IIS7Request.cpp
+++ b/iis7_shib/IIS7Request.cpp
@@ -448,6 +448,7 @@ void IIS7Request::logFatal(const string& operation, HRESULT hr) const
 
 void IIS7Request::throwError(const string& operation, HRESULT hr) const
 {
+    logFatal(operation, hr);
     string msg(operation + " failed: " + lexical_cast<string>(hr));
     throw IOException(msg.c_str());
 }
diff --git a/iis7_shib/ShibHttpModule.cpp b/iis7_shib/ShibHttpModule.cpp
index 4894d65a..ad528a40 100644
--- a/iis7_shib/ShibHttpModule.cpp
+++ b/iis7_shib/ShibHttpModule.cpp
@@ -21,9 +21,11 @@
 #include "IIS7_shib.hpp"
 
 #include <xmltooling/util/NDC.h>
+#include <xmltooling/io/HTTPResponse.h>
 
 #include "ShibHttpModule.hpp"
 #include "IIS7Request.hpp"
+#include "IIS7_shib.hpp"
 
 #include <process.h>
 #include <winreg.h>
@@ -115,7 +117,29 @@ ShibHttpModule::OnBeginRequest(
     _In_ IHttpEventProvider *   pProvider
 )
 {
-    return DoHandler(pHttpContext, pProvider);
+    IHttpResponse* res = pHttpContext->GetResponse();
+    try {
+        return DoHandler(pHttpContext, pProvider);
+    }
+    catch (const bad_alloc&) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Memory Error", 0, E_OUTOFMEMORY);
+    }
+    catch (long e) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Win32 Error", 0, HRESULT_FROM_WIN32(e));
+    }
+    catch (const std::exception& e) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), e.what());
+    }
+    catch (...) {
+        if (g_catchAll) {
+            res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Error Caught");
+        }
+        else {
+            throw;
+        }
+    }
+    pHttpContext->SetRequestHandled();
+    return RQ_NOTIFICATION_FINISH_REQUEST;
 }
 
 // RQ_AUTHENTICATE_REQUEST 
@@ -125,5 +149,27 @@ ShibHttpModule::OnAuthenticateRequest(
     _In_ IAuthenticationProvider *  pProvider
 )
 {
-    return DoFilter(pHttpContext, pProvider);
+    IHttpResponse* res = pHttpContext->GetResponse();
+    try {
+        return DoFilter(pHttpContext, pProvider);
+    }
+    catch (const bad_alloc&) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Memory Error", 0, E_OUTOFMEMORY);
+    }
+    catch (long e) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Win32 Error", 0, HRESULT_FROM_WIN32(e));
+    }
+    catch (const std::exception& e) {
+        res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), e.what());
+    }
+    catch (...) {
+        if (g_catchAll) {
+            res->SetStatus(static_cast<USHORT>(xmltooling::HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR), "Fatal Server Error Caught");
+        }
+        else {
+            throw;
+        }
+    }
+    pHttpContext->SetRequestHandled();
+    return RQ_NOTIFICATION_FINISH_REQUEST;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list