summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-04-27 11:29:14 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-27 11:48:41 (GMT)
commit860d265a878ca444fca358f468a32df32a7f4444 (patch)
tree1d379bb1966960d87b3da53fc2ecbf3da54dca7b /Swiften
parent5d8c328e236f57d7390d32f9ea7bd17a31e1e740 (diff)
downloadswift-860d265a878ca444fca358f468a32df32a7f4444.zip
swift-860d265a878ca444fca358f468a32df32a7f4444.tar.bz2
Zero memory more securely in SafeByteArray.
Change-Id: I0d9db512e0c525d87fddc26dc73ea95d2b54b54d
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Base/SConscript1
-rw-r--r--Swiften/Base/SafeAllocator.cpp27
-rw-r--r--Swiften/Base/SafeAllocator.h8
3 files changed, 34 insertions, 2 deletions
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index 754164b..b56db8c 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -4,6 +4,7 @@ objects = swiften_env.SwiftenObject([
"ByteArray.cpp",
"DateTime.cpp",
"SafeByteArray.cpp",
+ "SafeAllocator.cpp",
"Error.cpp",
"Log.cpp",
"Paths.cpp",
diff --git a/Swiften/Base/SafeAllocator.cpp b/Swiften/Base/SafeAllocator.cpp
new file mode 100644
index 0000000..d61d8b9
--- /dev/null
+++ b/Swiften/Base/SafeAllocator.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Base/SafeByteArray.h>
+
+#include <Swiften/Base/Platform.h>
+#ifdef SWIFTEN_PLATFORM_WINDOWS
+#include <windows.h>
+#endif
+
+namespace Swift {
+
+void secureZeroMemory(char* memory, size_t numberOfBytes) {
+#ifdef SWIFTEN_PLATFORM_WINDOWS
+ SecureZeroMemory(memory, numberOfBytes);
+#else
+ volatile char* p = memory;
+ for (size_t i = 0; i < numberOfBytes; ++i) {
+ *(p++) = 0;
+ }
+#endif
+}
+
+}
diff --git a/Swiften/Base/SafeAllocator.h b/Swiften/Base/SafeAllocator.h
index f59119e..b01d77d 100644
--- a/Swiften/Base/SafeAllocator.h
+++ b/Swiften/Base/SafeAllocator.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,6 +10,8 @@
#include <algorithm>
namespace Swift {
+ void secureZeroMemory(char* memory, size_t numberOfBytes);
+
template<typename T>
class SafeAllocator : public std::allocator<T> {
public:
@@ -23,8 +25,10 @@ namespace Swift {
~SafeAllocator() throw() {}
void deallocate (T* p, size_t num) {
- std::fill(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p + num), 0);
+ secureZeroMemory(reinterpret_cast<char*>(p), num);
std::allocator<T>::deallocate(p, num);
}
+
+ private:
};
}