Use a fixed time when fuzzing.
authorKurt Roeckx <kurt@roeckx.be>
Sun, 19 Feb 2017 15:59:25 +0000 (16:59 +0100)
committerKurt Roeckx <kurt@roeckx.be>
Sun, 16 Apr 2017 17:30:15 +0000 (19:30 +0200)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
GH: #2683

fuzz/client.c
fuzz/server.c

index 9404a95a6838983af3cef3b8f3df1487bcfa97f0..622d782b2cb3783f07bf41cab3e02b5f81905e7f 100644 (file)
@@ -8,6 +8,7 @@
  * or in the file LICENSE in the source distribution.
  */
 
+#include <time.h>
 #include <openssl/rand.h>
 #include <openssl/ssl.h>
 #include <openssl/rsa.h>
@@ -25,6 +26,23 @@ extern int rand_predictable;
 /* unused, to avoid warning. */
 static int idx;
 
+#define FUZZTIME 1485898104
+
+#define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; }
+
+/*
+ * This might not in all cases and still get the current time
+ * instead of the fixed time. This will just result in things
+ * not being fully reproducible and have a slightly different
+ * coverage.
+ */
+#if defined(_WIN32) && defined(_TIME64_T_DEFINED)
+time64_t _time64(time64_t *t) TIME_IMPL(t)
+#endif
+#if !defined(_WIN32) || !defined(_MSC_VER)
+time_t time(time_t *t) TIME_IMPL(t)
+#endif
+
 int FuzzerInitialize(int *argc, char ***argv)
 {
     STACK_OF(SSL_COMP) *comp_methods;
index 5bbba1c26aed941da347e9d6f7d19aa4b6beadcd..8c5e2d8d4a4627a36327f2764cff1a1acbd3ea2d 100644 (file)
@@ -12,7 +12,7 @@
 
 /* Test first part of SSL server handshake. */
 
-
+#include <time.h>
 #include <openssl/rand.h>
 #include <openssl/ssl.h>
 #include <openssl/rsa.h>
@@ -473,6 +473,23 @@ extern int rand_predictable;
 /* unused, to avoid warning. */
 static int idx;
 
+#define FUZZTIME 1485898104
+
+#define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; }
+
+/*
+ * This might not in all cases and still get the current time
+ * instead of the fixed time. This will just result in things
+ * not being fully reproducible and have a slightly different
+ * coverage.
+ */
+#if defined(_WIN32) && defined(_TIME64_T_DEFINED)
+time64_t _time64(time64_t *t) TIME_IMPL(t)
+#endif
+#if !defined(_WIN32) || !defined(_MSC_VER)
+time_t time(time_t *t) TIME_IMPL(t)
+#endif
+
 int FuzzerInitialize(int *argc, char ***argv)
 {
     STACK_OF(SSL_COMP) *comp_methods;