Skip to content

Commit

Permalink
Bug 1315193 - Fuzzing mode: ssl_Time() must return a constant value r…
Browse files Browse the repository at this point in the history
…=franziskus

Differential Revision: https://nss-review.dev.mozaws.net/D19
  • Loading branch information
Tim Taubert committed Nov 4, 2016
1 parent bcb1a4c commit 0f22e53
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions gtests/ssl_gtest/manifest.mn
Expand Up @@ -23,6 +23,7 @@ CPPSRCS = \
ssl_ecdh_unittest.cc \
ssl_ems_unittest.cc \
ssl_extension_unittest.cc \
ssl_fuzz_unittest.cc \
ssl_gtest.cc \
ssl_hrr_unittest.cc \
ssl_loopback_unittest.cc \
Expand Down
25 changes: 25 additions & 0 deletions gtests/ssl_gtest/ssl_fuzz_unittest.cc
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ssl.h"
#include "sslimpl.h"

#include "gtest/gtest.h"

namespace nss_test {

#ifdef UNSAFE_FUZZER_MODE

class TlsFuzzTest : public ::testing::Test {};

// Ensure that ssl_Time() returns a constant value.
TEST_F(TlsFuzzTest, Fuzz_SSL_Time_Constant) {
PRInt32 now = ssl_Time();
PR_Sleep(PR_SecondsToInterval(2));
EXPECT_EQ(ssl_Time(), now);
}

#endif

}
1 change: 1 addition & 0 deletions gtests/ssl_gtest/ssl_gtest.gyp
Expand Up @@ -23,6 +23,7 @@
'ssl_ecdh_unittest.cc',
'ssl_ems_unittest.cc',
'ssl_extension_unittest.cc',
'ssl_fuzz_unittest.cc',
'ssl_gtest.cc',
'ssl_hrr_unittest.cc',
'ssl_loopback_unittest.cc',
Expand Down
5 changes: 5 additions & 0 deletions lib/ssl/ssl.gyp
Expand Up @@ -63,6 +63,11 @@
'NSS_SSL_ENABLE_ZLIB',
],
}],
[ 'fuzz==1', {
'defines': [
'UNSAFE_FUZZER_MODE',
],
}],
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports',
Expand Down
4 changes: 4 additions & 0 deletions lib/ssl/sslnonce.c
Expand Up @@ -440,6 +440,10 @@ SSL_ClearSessionCache(void)
PRUint32
ssl_Time(void)
{
#ifdef UNSAFE_FUZZER_MODE
return 1234;
#endif

PRUint32 myTime;
#if defined(XP_UNIX) || defined(XP_WIN) || defined(_WINDOWS) || defined(XP_BEOS)
myTime = time(NULL); /* accurate until the year 2038. */
Expand Down
3 changes: 2 additions & 1 deletion tests/ssl_gtests/ssl_gtests.sh
Expand Up @@ -127,7 +127,8 @@ ssl_gtest_start()
SSLGTESTREPORT="${SSLGTESTDIR}/report.xml"
PARSED_REPORT="${SSLGTESTDIR}/report.parsed"
echo "executing ssl_gtest"
${BINDIR}/ssl_gtest -d "${SSLGTESTDIR}" --gtest_output=xml:"${SSLGTESTREPORT}"
${BINDIR}/ssl_gtest -d "${SSLGTESTDIR}" --gtest_output=xml:"${SSLGTESTREPORT}" \
--gtest_filter="${GTESTFILTER-*}"
html_msg $? 0 "ssl_gtest run successfully"
echo "executing sed to parse the xml report"
sed -f ${COMMON}/parsegtestreport.sed "${SSLGTESTREPORT}" > "${PARSED_REPORT}"
Expand Down

0 comments on commit 0f22e53

Please sign in to comment.