[cpp-xmltooling COMMIT] in /branches/REL_1/xmltooling: impl/MemoryStorageService.cpp util/ReplayCache.cpp util/Replay...

noreply at shibboleth.net noreply at shibboleth.net
Mon Oct 10 18:11:15 BST 2011


Author: scantor
Date: Mon Oct 10 18:11:14 2011
New Revision: 912

URL: http://svn.shibboleth.net/view/cpp-xmltooling?rev=912&view=rev
Log:
Expose size limits on storage in API, and add overflow detection logic to replay cache.

Modified:
    branches/REL_1/xmltooling/impl/MemoryStorageService.cpp
    branches/REL_1/xmltooling/util/ReplayCache.cpp
    branches/REL_1/xmltooling/util/ReplayCache.h
    branches/REL_1/xmltooling/util/StorageService.cpp
    branches/REL_1/xmltooling/util/StorageService.h

Modified: branches/REL_1/xmltooling/impl/MemoryStorageService.cpp
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/impl/MemoryStorageService.cpp?rev=912&r1=911&r2=912&view=diff
==============================================================================
--- branches/REL_1/xmltooling/impl/MemoryStorageService.cpp (original)
+++ branches/REL_1/xmltooling/impl/MemoryStorageService.cpp Mon Oct 10 18:11:14 2011
@@ -40,12 +40,21 @@
 
 using xercesc::DOMElement;
 
+namespace {
+    // Reasonably extended sizes to avoid callers needing to shrink unduly.
+    static const XMLTOOL_DLLLOCAL StorageService::Capabilities g_memCaps(0x4000, 0x4000, 0x4000);
+};
+
 namespace xmltooling {
     class XMLTOOL_DLLLOCAL MemoryStorageService : public StorageService
     {
     public:
         MemoryStorageService(const DOMElement* e);
         virtual ~MemoryStorageService();
+
+        const Capabilities& getCapabilities() const {
+            return g_memCaps;
+        }
 
         bool createString(const char* context, const char* key, const char* value, time_t expiration);
         int readString(const char* context, const char* key, string* pvalue=nullptr, time_t* pexpiration=nullptr, int version=0);

Modified: branches/REL_1/xmltooling/util/ReplayCache.cpp
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/util/ReplayCache.cpp?rev=912&r1=911&r2=912&view=diff
==============================================================================
--- branches/REL_1/xmltooling/util/ReplayCache.cpp (original)
+++ branches/REL_1/xmltooling/util/ReplayCache.cpp Mon Oct 10 18:11:14 2011
@@ -25,16 +25,19 @@
  */
 
 #include "internal.h"
+#include "logging.h"
+#include "security/SecurityHelper.h"
 #include "util/ReplayCache.h"
-#include "util/StorageService.h"
 
+using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace std;
 
-ReplayCache::ReplayCache(StorageService* storage) : m_owned(storage==nullptr), m_storage(storage)
+ReplayCache::ReplayCache(StorageService* storage)
+    : m_owned(storage==nullptr),
+        m_storage(storage ? storage : XMLToolingConfig::getConfig().StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE, nullptr)),
+        m_storageCaps(m_storage->getCapabilities())
 {
-    if (!m_storage)
-        m_storage = XMLToolingConfig::getConfig().StorageServiceManager.newPlugin(MEMORY_STORAGE_SERVICE, nullptr);
 }
 
 ReplayCache::~ReplayCache()
@@ -45,6 +48,30 @@
 
 bool ReplayCache::check(const char* context, const char* s, time_t expires)
 {
+    if (strlen(context) > m_storageCaps.getContextSize()) {
+        // This is a design/coding failure.
+        Category::getInstance(XMLTOOLING_LOGCAT".ReplayCache").error(
+            "context (%s) too long for StorageService (limit %u)", context, m_storageCaps.getContextSize()
+            );
+        return false;
+    }
+    else if (strlen(s) > m_storageCaps.getKeySize()) {
+        // This is something to work around with a hash.
+#ifndef XMLTOOLING_NO_XMLSEC
+        string h = SecurityHelper::doHash("SHA1", s, strlen(s));
+        // In storage already?
+        if (m_storage->readString(context, h.c_str()))
+            return false;
+        m_storage->createString(context, h.c_str(), "x", expires);
+        return true;
+#else
+        Category::getInstance(XMLTOOLING_LOGCAT".ReplayCache").error(
+            "key (%s) too long for StorageService (limit %u)", s, m_storageCaps.getKeySize()
+            );
+        return false;
+#endif
+    }
+
     // In storage already?
     if (m_storage->readString(context, s))
         return false;

Modified: branches/REL_1/xmltooling/util/ReplayCache.h
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/util/ReplayCache.h?rev=912&r1=911&r2=912&view=diff
==============================================================================
--- branches/REL_1/xmltooling/util/ReplayCache.h (original)
+++ branches/REL_1/xmltooling/util/ReplayCache.h Mon Oct 10 18:11:14 2011
@@ -28,6 +28,7 @@
 #define __xmltooling_replay_h__
 
 #include <xmltooling/base.h>
+#include <xmltooling/util/StorageService.h>
 
 namespace xmltooling {
 
@@ -74,6 +75,7 @@
     private:
         bool m_owned;
         StorageService* m_storage;
+        const StorageService::Capabilities& m_storageCaps;
     };
 };
 

Modified: branches/REL_1/xmltooling/util/StorageService.cpp
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/util/StorageService.cpp?rev=912&r1=911&r2=912&view=diff

[... 203 lines stripped ...]


More information about the commits mailing list