summaryrefslogtreecommitdiff
path: root/test.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-09-16 11:27:15 -0400
committerJeffrey Walton <noloader@gmail.com>2016-09-16 11:27:15 -0400
commit399a1546de71f41598c15edada28e7f0d616f541 (patch)
tree530160789358a3303be180df2d8529c82782156b /test.cpp
parentfca5fbb36169a7522e6c533df9c322d47e3dc6bb (diff)
downloadcryptopp-git-399a1546de71f41598c15edada28e7f0d616f541.tar.gz
Add CRYPTOPP_ASSERT (Issue 277, CVE-2016-7420)
trap.h and CRYPTOPP_ASSERT has existed for over a year in Master. We deferred on the cut-over waiting for a minor version bump (5.7). We have to use it now due to CVE-2016-7420
Diffstat (limited to 'test.cpp')
-rw-r--r--test.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/test.cpp b/test.cpp
index bf0ddc02..52dd740a 100644
--- a/test.cpp
+++ b/test.cpp
@@ -21,6 +21,7 @@
#include "whrlpool.h"
#include "tiger.h"
#include "smartptr.h"
+#include "trap.h"
#include "validate.h"
#include "bench.h"
@@ -128,6 +129,11 @@ RandomNumberGenerator & GlobalRNG()
return dynamic_cast<RandomNumberGenerator&>(s_globalRNG);
}
+// See misc.h and trap.h for comments and usage
+#if CRYPTOPP_DEBUG && (defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE))
+static const SignalHandler<SIGTRAP, false> s_dummyHandler;
+#endif
+
int CRYPTOPP_API main(int argc, char *argv[])
{
#ifdef _CRTDBG_LEAK_CHECK_DF
@@ -271,7 +277,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
// compute MAC
member_ptr<MessageAuthenticationCode> pMac(NewIntegrityCheckingMAC());
- assert(pMac->DigestSize() == sizeof(mac));
+ CRYPTOPP_ASSERT(pMac->DigestSize() == sizeof(mac));
MeterFilter f(new HashFilter(*pMac, new ArraySink(mac, sizeof(mac))));
f.AddRangeToSkip(0, checksumPos, 4);
f.AddRangeToSkip(0, certificateTableDirectoryPos, 8);
@@ -628,7 +634,7 @@ void DecryptFile(const char *in, const char *out, const char *passPhrase)
void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
{
- assert(nShares >= 1 && nShares<=1000);
+ CRYPTOPP_ASSERT(nShares >= 1 && nShares<=1000);
if (nShares < 1 || nShares > 1000)
throw InvalidArgument("SecretShareFile: " + IntToString(nShares) + " is not in range [1, 1000]");
@@ -658,7 +664,7 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha
void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
{
- assert(threshold >= 1 && threshold <=1000);
+ CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
if (threshold < 1 || threshold > 1000)
throw InvalidArgument("SecretRecoverFile: " + IntToString(threshold) + " is not in range [1, 1000]");
@@ -685,7 +691,7 @@ void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFi
void InformationDisperseFile(int threshold, int nShares, const char *filename)
{
- assert(threshold >= 1 && threshold <=1000);
+ CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
if (threshold < 1 || threshold > 1000)
throw InvalidArgument("InformationDisperseFile: " + IntToString(nShares) + " is not in range [1, 1000]");
@@ -712,7 +718,7 @@ void InformationDisperseFile(int threshold, int nShares, const char *filename)
void InformationRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
{
- assert(threshold<=1000);
+ CRYPTOPP_ASSERT(threshold<=1000);
if (threshold < 1 || threshold > 1000)
throw InvalidArgument("InformationRecoverFile: " + IntToString(threshold) + " is not in range [1, 1000]");
@@ -811,7 +817,7 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con
sockListen.Bind(sourcePort);
int err = setsockopt(sockListen, IPPROTO_TCP, TCP_NODELAY, "\x01", 1);
- assert(err == 0);
+ CRYPTOPP_ASSERT(err == 0);
if(err != 0)
throw Socket::Err(sockListen, "setsockopt", sockListen.GetLastError());
@@ -963,9 +969,9 @@ bool Validate(int alg, bool thorough, const char *seedInput)
const time_t endTime = time(NULL);
err = localtime_s(&localTime, &endTime);
- assert(err == 0);
+ CRYPTOPP_ASSERT(err == 0);
err = asctime_s(timeBuf, sizeof(timeBuf), &localTime);
- assert(err == 0);
+ CRYPTOPP_ASSERT(err == 0);
cout << "\nTest ended at " << timeBuf;
#else