From 1c017edac369a40c9a1633b0560e5f0d85b4e39e Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Wed, 20 Sep 2017 16:54:56 -0500 Subject: [PATCH 1/2] Use correct sign for state file clock skew or_state_load() was using an incorrect sign convention when calling clock_skew_warning() to warn about state file clock skew. This caused the wording of the warning to be incorrect about the direction of the skew. --- changes/bug23606 | 4 ++++ src/or/statefile.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changes/bug23606 diff --git a/changes/bug23606 b/changes/bug23606 new file mode 100644 index 0000000000..77f4d0cb9e --- /dev/null +++ b/changes/bug23606 @@ -0,0 +1,4 @@ + o Minor bugfixes (bootstrapping): + - When warning about state file clock skew, report the correct + direction for the detected skew. Fixes bug 23606; bugfix on + 0.2.8.1-alpha. diff --git a/src/or/statefile.c b/src/or/statefile.c index 9647aa8834..86f26419be 100644 --- a/src/or/statefile.c +++ b/src/or/statefile.c @@ -404,8 +404,8 @@ or_state_load(void) log_info(LD_GENERAL, "Loaded state from \"%s\"", fname); /* Warn the user if their clock has been set backwards, * they could be tricked into using old consensuses */ - time_t apparent_skew = new_state->LastWritten - time(NULL); - if (apparent_skew > 0) + time_t apparent_skew = time(NULL) - new_state->LastWritten; + if (apparent_skew < 0) clock_skew_warning(NULL, (long)apparent_skew, 1, LD_GENERAL, "local state file", fname); } else { From ad814cad41a101a3afd03ed0fdc55e2efd696abf Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Wed, 20 Sep 2017 18:47:15 -0500 Subject: [PATCH 2/2] Avoid assertion failure for state file clock skew The clock_skew_warning() refactoring allowed calls from or_state_load() to control_event_bootstrap_problem() to occur prior bootstrap phase 0, causing an assertion failure. Initialize the bootstrap status prior to calling clock_skew_warning() from or_state_load(). --- changes/bug23607 | 4 ++++ src/or/statefile.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changes/bug23607 diff --git a/changes/bug23607 b/changes/bug23607 new file mode 100644 index 0000000000..7aa48a94c6 --- /dev/null +++ b/changes/bug23607 @@ -0,0 +1,4 @@ + o Minor bugfixes (bootstrapping): + - Avoid an assertion failure when logging a state file clock skew + very early in bootstrapping. Fixes bug 23607; bugfix on + 0.3.2.1-alpha. diff --git a/src/or/statefile.c b/src/or/statefile.c index 86f26419be..2d579a0220 100644 --- a/src/or/statefile.c +++ b/src/or/statefile.c @@ -34,6 +34,7 @@ #include "config.h" #include "confparse.h" #include "connection.h" +#include "control.h" #include "entrynodes.h" #include "hibernate.h" #include "rephist.h" @@ -405,9 +406,14 @@ or_state_load(void) /* Warn the user if their clock has been set backwards, * they could be tricked into using old consensuses */ time_t apparent_skew = time(NULL) - new_state->LastWritten; - if (apparent_skew < 0) + if (apparent_skew < 0) { + /* Initialize bootstrap event reporting because we might call + * clock_skew_warning() before the bootstrap state is + * initialized, causing an asserttion failure. */ + control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0); clock_skew_warning(NULL, (long)apparent_skew, 1, LD_GENERAL, "local state file", fname); + } } else { log_info(LD_GENERAL, "Initialized state"); }